Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Eclipse stuff
/.classpath
/.project
/.settings
/.checkstyle

# we use maven!
/build.xml

# maven
dependency-reduced-pom.xml

# intellij
*.iml
*.ipr
*.iws
.idea/

# Build stuff
/target
/classes
Binary file removed out/artifacts/stayput_jar/stayput.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<version>Spigot-API 1.13.1-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-android -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Manifest-Version: 1.0
Main-Class: nl.zandervdm.stayput.Main
Main-Class: nl.zandervdm.stayput.StayPut

31 changes: 28 additions & 3 deletions src/main/java/nl/zandervdm/stayput/Commands/StayputCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package nl.zandervdm.stayput.Commands;

import nl.zandervdm.stayput.Main;
import com.google.common.collect.*;
import nl.zandervdm.stayput.StayPut;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import java.util.HashMap;

public class StayputCommand implements CommandExecutor {

protected Main plugin;
protected StayPut plugin;

public StayputCommand(Main plugin) {
public StayputCommand(StayPut plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {

if(strings.length == 0){
Expand All @@ -30,16 +34,37 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}
this.plugin.reloadConfig();
this.plugin.setupConfig();
this.plugin.checkTableRebuild();
// Re-setup the dimensions if the config got altered.
this.plugin.setupDimensions();
this.sendMessage(commandSender, "Config has been reloaded!");
return true;
}

if(executedCommand.equals("listworlds")) {
this.sendMessage(commandSender, "-- Dimension List --");
ImmutableMultimap<String,String> dimensions = this.plugin.getDimensionManager().getDimensions();
for(String dimension_name : dimensions.keySet() ) {
this.sendMessage(commandSender, dimension_name + ":");
dimensions.get(dimension_name).forEach(world_name -> {
this.sendMessage(commandSender," - " + world_name);
});
}
}

if(executedCommand.equals("rebuildTables")) {
this.sendMessage(commandSender, "-- Deleting and Rebuilding Position --");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a permission check here? I assume not everyone should be allowed to run this command.

this.plugin.rebuildTables();
}

return true;
}

protected void sendInfoMessage(CommandSender commandSender){
this.sendMessage(commandSender, "Available commands:");
this.sendMessage(commandSender, "/stayput reload - Reloads the config files");
this.sendMessage(commandSender, "/stayput listdimensions - Lists all the dimensions");
this.sendMessage(commandSender, "/stayput rebuildTables - DO NOT RUN THIS");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe don't add it here if you shouldn't run it? Or add a better message to know why people shouldn't run it.

}

protected void sendMessage(CommandSender commandSender, String message){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
package nl.zandervdm.stayput.Listeners;

import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
import javafx.geometry.Pos;
import nl.zandervdm.stayput.Main;
import nl.zandervdm.stayput.Models.Position;
import com.onarandombox.MultiversePortals.event.MVPortalEvent;
import nl.zandervdm.stayput.StayPut;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;

import java.sql.SQLException;
import java.util.List;

public class PlayerTeleportEventListener implements Listener {

protected Main plugin;
private StayPut plugin;

public PlayerTeleportEventListener(Main plugin) {
public PlayerTeleportEventListener(StayPut plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPlayerTeleportEvent(MVTeleportEvent event){
if(Main.config.getBoolean("debug")) this.plugin.getLogger().info("PlayerTeleportEvent activated");
if(StayPut.config.getBoolean("debug")) this.plugin.getLogger().info("PlayerTeleportEvent activated");
Player player = event.getTeleportee();
World fromWorld = event.getFrom().getWorld();
World toWorld = event.getDestination().getLocation(player).getWorld();

if(!this.plugin.getRuleManager().shouldUpdateLocation(player, event.getFrom(), event.getDestination().getLocation(player))){
return;
Expand All @@ -39,61 +31,105 @@ public void onPlayerTeleportEvent(MVTeleportEvent event){
//he left the previous world
this.plugin.getPositionRepository().updateLocationForPlayer(player, event.getFrom());

Location previousLocation = this.plugin.getRuleManager().shouldTeleportPlayer(player, event.getFrom(), event.getDestination().getLocation(player));
Location previousLocation = this.plugin.getRuleManager().shouldTeleportPlayer(player, event.getDestination().getLocation(player));

if(previousLocation != null) {
if(this.isPressureplate(previousLocation)){
if(this.isPressurePlate(previousLocation)){
// Find a valid spot around the location
Location newLocation = this.findAvailableLocation(previousLocation);
if(newLocation != null) previousLocation = newLocation;
}

//There is a location, and the player should teleport, so teleport him
if (Main.config.getBoolean("debug"))
if (StayPut.config.getBoolean("debug"))
this.plugin.getLogger().info("Teleporting player to his previous location");
event.setCancelled(true);
player.teleport(previousLocation);
}
}

protected boolean isPressureplate(Location toLocation) {
@EventHandler
public void onPlayerPortalEvent(MVPortalEvent event) {
if(StayPut.config.getBoolean("debug")) this.plugin.getLogger().info("PlayerPortalEvent activated");
Player player = event.getTeleportee();

if(!this.plugin.getRuleManager().shouldUpdateLocation(player, event.getFrom(), event.getDestination().getLocation(player))){
return;
}

//We should always update the previous location for the previous world for this player because at this point
//he left the previous world
this.plugin.getPositionRepository().updateLocationForPlayer(player, event.getFrom());

Location previousLocation = this.plugin.getRuleManager().shouldTeleportPlayer(player, event.getDestination().getLocation(player));

if(previousLocation != null) {
if(this.isPressurePlate(previousLocation)){
// Find a valid spot around the location
Location newLocation = this.findAvailableLocation(previousLocation);
if(newLocation != null) previousLocation = newLocation;
}

//There is a location, and the player should teleport, so teleport him
if (StayPut.config.getBoolean("debug"))
this.plugin.getLogger().info("Teleporting player to his previous location");
event.setCancelled(true);
player.teleport(previousLocation);
}
}

private boolean isPressurePlate(Location toLocation) {
Location blockBelow = new Location(toLocation.getWorld(), toLocation.getX(), toLocation.getY()-1, toLocation.getZ());
if(blockBelow.getBlock().getType().equals(Material.STONE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.WOOD_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.IRON_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.GOLD_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.STONE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.GOLD_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.IRON_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.WOOD_PLATE)) return true;
if(toLocation.getBlock().getType().equals(Material.STONE_PLATE)) return true;
if(toLocation.getBlock().getType().equals(Material.WOOD_PLATE)) return true;
if(toLocation.getBlock().getType().equals(Material.IRON_PLATE)) return true;
if(toLocation.getBlock().getType().equals(Material.GOLD_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.ACACIA_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.BIRCH_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.DARK_OAK_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.JUNGLE_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.OAK_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.SPRUCE_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.STONE_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.HEAVY_WEIGHTED_PRESSURE_PLATE)) return true;
if(blockBelow.getBlock().getType().equals(Material.LIGHT_WEIGHTED_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.ACACIA_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.BIRCH_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.DARK_OAK_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.JUNGLE_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.OAK_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.SPRUCE_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.STONE_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.HEAVY_WEIGHTED_PRESSURE_PLATE)) return true;
if(toLocation.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.LIGHT_WEIGHTED_PRESSURE_PLATE)) return true;
return false;
}

protected Location findAvailableLocation(Location location) {
private Location findAvailableLocation(Location location) {
//The current given location isn't valid (most likely it is a pressure plate)
//Get the location in front, back, left and right of it and check if it is air.
//Get the location in front, back, left and right of it and check if it is air or water.
//Also check the block above it to make sure the block can't suffocate.
Location block1Down = new Location(location.getWorld(), location.getX()-1, location.getY(), location.getZ(), location.getYaw(), location.getPitch());
Location block2Down = new Location(location.getWorld(), location.getX()+1, location.getY(), location.getZ(), location.getYaw(), location.getPitch());
Location block3Down = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()-1, location.getYaw(), location.getPitch());
Location block4Down = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()+1, location.getYaw(), location.getPitch());

if(block1Down.getBlock().getType().equals(Material.AIR)){
Location block1Up = new Location(location.getWorld(), location.getX()-1, location.getY()+1, location.getZ());
if(block1Up.getBlock().getType().equals(Material.AIR)) return block1Down;
}else if(block2Down.getBlock().getType().equals(Material.AIR)){
Location block2Up = new Location(location.getWorld(), location.getX()+1, location.getY()+1, location.getZ());
if(block2Up.getBlock().getType().equals(Material.AIR)) return block2Down;
}else if(block3Down.getBlock().getType().equals(Material.AIR)){
Location block3Up = new Location(location.getWorld(), location.getX(), location.getY()+1, location.getZ()-1);
if(block3Up.getBlock().getType().equals(Material.AIR)) return block3Down;
}else if(block4Down.getBlock().getType().equals(Material.AIR)){
Location block4Up = new Location(location.getWorld(), location.getX(), location.getY()+1, location.getZ()+1);
if(block4Up.getBlock().getType().equals(Material.AIR)) return block4Down;
Location location1Down = new Location(location.getWorld(), location.getX()-1, location.getY(), location.getZ(), location.getYaw(), location.getPitch());
Location location2Down = new Location(location.getWorld(), location.getX()+1, location.getY(), location.getZ(), location.getYaw(), location.getPitch());
Location location3Down = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()-1, location.getYaw(), location.getPitch());
Location location4Down = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()+1, location.getYaw(), location.getPitch());
Material block1Down = location1Down.getBlock().getType();
Material block2Down = location2Down.getBlock().getType();
Material block3Down = location3Down.getBlock().getType();
Material block4Down = location4Down.getBlock().getType();

if(block1Down.equals(Material.AIR) || block1Down.equals(Material.WATER)){
Location location1Up = new Location(location.getWorld(), location.getX()-1, location.getY()+1, location.getZ(), location.getYaw(), location.getPitch());
Material block1Up = location1Up.getBlock().getType();
if(block1Up.equals(Material.AIR) || block1Up.equals(Material.WATER)) return location1Down;
}else if(block2Down.equals(Material.AIR) || block2Down.equals(Material.WATER)){
Location location2Up = new Location(location.getWorld(), location.getX()+1, location.getY()+1, location.getZ(), location.getYaw(), location.getPitch());
Material block2Up = location2Up.getBlock().getType();
if(block2Up.equals(Material.AIR) || block2Up.equals(Material.WATER)) return location2Down;
}else if(block3Down.equals(Material.AIR) || block3Down.equals(Material.WATER)){
Location location3Up = new Location(location.getWorld(), location.getX(), location.getY()+1, location.getZ()-1, location.getYaw(), location.getPitch());
Material block3Up = location3Up.getBlock().getType();
if(block3Up.equals(Material.AIR) || block3Up.equals(Material.WATER)) return location3Down;
}else if(block4Down.equals(Material.AIR) || block4Down.equals(Material.WATER)){
Location location4Up = new Location(location.getWorld(), location.getX(), location.getY()+1, location.getZ()+1, location.getYaw(), location.getPitch());
Material block4Up = location4Up.getBlock().getType();
if(block4Up.equals(Material.AIR) || block4Up.equals(Material.WATER)) return location4Down;
}
return null;
}
Expand Down
Loading