Let's try out the move protection, maybe this will work the first time
This commit is contained in:
		@@ -7,8 +7,10 @@ import org.bukkit.Bukkit;
 | 
				
			|||||||
import org.bukkit.Location;
 | 
					import org.bukkit.Location;
 | 
				
			||||||
import org.bukkit.World;
 | 
					import org.bukkit.World;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.util.Vector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.graywolf336.jail.JailMain;
 | 
					import com.graywolf336.jail.JailMain;
 | 
				
			||||||
 | 
					import com.graywolf336.jail.Util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Represents a Jail, contains the prisoners and the cells.
 | 
					/** Represents a Jail, contains the prisoners and the cells.
 | 
				
			||||||
 * 
 | 
					 * 
 | 
				
			||||||
@@ -314,4 +316,18 @@ public class Jail {
 | 
				
			|||||||
		if (loc.getWorld().getName().equalsIgnoreCase(getTeleportIn().getWorld().getName())) return (double) Integer.MAX_VALUE;
 | 
							if (loc.getWorld().getName().equalsIgnoreCase(getTeleportIn().getWorld().getName())) return (double) Integer.MAX_VALUE;
 | 
				
			||||||
		else return loc.distance(getTeleportIn());
 | 
							else return loc.distance(getTeleportIn());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Returns whether the given location is inside this Jail.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param loc to check whether is inside this jail
 | 
				
			||||||
 | 
						 * @return True if the location is in the jail, false if it isn't
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public boolean isInside(Location loc) {
 | 
				
			||||||
 | 
							if(loc.getWorld().getName().equalsIgnoreCase(world)) {
 | 
				
			||||||
 | 
								return Util.isInsideAB(loc.toVector(), new Vector(minX, minY, minZ), new Vector(maxX, maxY, maxZ));
 | 
				
			||||||
 | 
							}else {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,8 @@ public enum LangString {
 | 
				
			|||||||
	INTERACTIONBLOCKS ("actions"),
 | 
						INTERACTIONBLOCKS ("actions"),
 | 
				
			||||||
	/** Section for when a player interacts with an item that is blacklisted. */
 | 
						/** Section for when a player interacts with an item that is blacklisted. */
 | 
				
			||||||
	INTERACTIONITEMS ("actions"),
 | 
						INTERACTIONITEMS ("actions"),
 | 
				
			||||||
 | 
						/** Section for when a player moves outside of the jail. */
 | 
				
			||||||
 | 
						MOVING ("actions"),
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	//Jailing section
 | 
						//Jailing section
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,8 @@ public enum Settings {
 | 
				
			|||||||
	JAILEDSTOREINVENTORY("jailing.jail.storeInventory"),
 | 
						JAILEDSTOREINVENTORY("jailing.jail.storeInventory"),
 | 
				
			||||||
	LOGJAILING("jailing.jail.logToConsole"),
 | 
						LOGJAILING("jailing.jail.logToConsole"),
 | 
				
			||||||
	MAXAFKTIME("jailing.during.maxAFKTime"),
 | 
						MAXAFKTIME("jailing.during.maxAFKTime"),
 | 
				
			||||||
 | 
						MOVEPENALTY("jailing.during.movePenalty"),
 | 
				
			||||||
 | 
						MOVEPROTECTION("jailing.during.moveProtection"),
 | 
				
			||||||
	OPENCHEST("jailing.during.openChest"),
 | 
						OPENCHEST("jailing.during.openChest"),
 | 
				
			||||||
	PREVENTINTERACTIONBLOCKS("jailing.during.preventInteractionBlocks"),
 | 
						PREVENTINTERACTIONBLOCKS("jailing.during.preventInteractionBlocks"),
 | 
				
			||||||
	PREVENTINTERACTIONBLOCKSPENALTY("jailing.during.preventInteractionBlocksPenalty"),
 | 
						PREVENTINTERACTIONBLOCKSPENALTY("jailing.during.preventInteractionBlocksPenalty"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,9 +11,13 @@ import org.bukkit.event.block.BlockBreakEvent;
 | 
				
			|||||||
import org.bukkit.event.block.BlockPlaceEvent;
 | 
					import org.bukkit.event.block.BlockPlaceEvent;
 | 
				
			||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
 | 
					import org.bukkit.event.player.PlayerCommandPreprocessEvent;
 | 
				
			||||||
import org.bukkit.event.player.PlayerInteractEvent;
 | 
					import org.bukkit.event.player.PlayerInteractEvent;
 | 
				
			||||||
 | 
					import org.bukkit.event.player.PlayerMoveEvent;
 | 
				
			||||||
 | 
					import org.bukkit.event.player.PlayerTeleportEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.graywolf336.jail.JailMain;
 | 
					import com.graywolf336.jail.JailMain;
 | 
				
			||||||
import com.graywolf336.jail.Util;
 | 
					import com.graywolf336.jail.Util;
 | 
				
			||||||
 | 
					import com.graywolf336.jail.beans.Jail;
 | 
				
			||||||
 | 
					import com.graywolf336.jail.beans.Prisoner;
 | 
				
			||||||
import com.graywolf336.jail.enums.LangString;
 | 
					import com.graywolf336.jail.enums.LangString;
 | 
				
			||||||
import com.graywolf336.jail.enums.Settings;
 | 
					import com.graywolf336.jail.enums.Settings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -316,4 +320,68 @@ public class ProtectionListener implements Listener {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						@EventHandler(ignoreCancelled=true)
 | 
				
			||||||
 | 
						public void moveProtection(PlayerMoveEvent event) {
 | 
				
			||||||
 | 
							//If we have the move protection enabled, then let's do it.
 | 
				
			||||||
 | 
							//Other wise we don't need to deal with it.
 | 
				
			||||||
 | 
							//TODO: Should probably figure out how to not register this, as this is called so many times per step
 | 
				
			||||||
 | 
							if(pl.getConfig().getBoolean(Settings.MOVEPROTECTION.getPath())) {
 | 
				
			||||||
 | 
								//Let's be sure the player we're dealing with is in jail
 | 
				
			||||||
 | 
								if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) {
 | 
				
			||||||
 | 
									Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getName());
 | 
				
			||||||
 | 
									Prisoner p = j.getPrisoner(event.getPlayer().getName());
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//If the player is being teleported, let's ignore it
 | 
				
			||||||
 | 
									if(p.isTeleporting()) {
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//They moved, so they're no longer afk
 | 
				
			||||||
 | 
									p.setAFKTime(0L);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//If the event's to location is NOT inside the jail, then let's do some action.
 | 
				
			||||||
 | 
									//For right now, we're only going to apply the time. Later we're going to do
 | 
				
			||||||
 | 
									//the guards, but first get a beta version out.
 | 
				
			||||||
 | 
									if (!j.isInside(event.getTo())) {
 | 
				
			||||||
 | 
										try {
 | 
				
			||||||
 | 
											long add = Util.getTime(pl.getConfig().getString(Settings.MOVEPENALTY.getPath()));
 | 
				
			||||||
 | 
											pl.getJailManager().getPrisoner(event.getPlayer().getName()).addTime(add);
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											String msg = "";
 | 
				
			||||||
 | 
											if(add == 0L) {
 | 
				
			||||||
 | 
												//Generate the protection message, provide the method with one argument
 | 
				
			||||||
 | 
												//which is the thing we are protecting against
 | 
				
			||||||
 | 
												msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.MOVING));
 | 
				
			||||||
 | 
											}else {
 | 
				
			||||||
 | 
												//Generate the protection message, provide the method with two arguments
 | 
				
			||||||
 | 
												//First is the time in minutes and second is the thing we are protecting against
 | 
				
			||||||
 | 
												msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
 | 
				
			||||||
 | 
														new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
 | 
				
			||||||
 | 
														pl.getJailIO().getLanguageString(LangString.MOVING) });
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											//Send the message
 | 
				
			||||||
 | 
											event.getPlayer().sendMessage(msg);
 | 
				
			||||||
 | 
										}catch(Exception e) {
 | 
				
			||||||
 | 
											pl.getLogger().severe("Moving (escaping) outside a jail penalty time is in the wrong format, please fix.");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										//If the prisoner is in a cell, then let's teleport them to the cell's in location
 | 
				
			||||||
 | 
										if(j.isJailedInACell(event.getPlayer().getName())) {
 | 
				
			||||||
 | 
											event.setTo(j.getCellPrisonerIsIn(event.getPlayer().getName()).getTeleport());
 | 
				
			||||||
 | 
										}else {
 | 
				
			||||||
 | 
											//Otherwise let's teleport them to the in location of the jail
 | 
				
			||||||
 | 
											event.setTo(j.getTeleportIn());
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						@EventHandler(ignoreCancelled=true)
 | 
				
			||||||
 | 
						public void onPlayerTeleport(PlayerTeleportEvent event) {
 | 
				
			||||||
 | 
							PlayerMoveEvent move = new PlayerMoveEvent(event.getPlayer(), event.getFrom(), event.getTo());
 | 
				
			||||||
 | 
							moveProtection(move);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,8 @@ jailing:
 | 
				
			|||||||
    foodControlMin: 10
 | 
					    foodControlMin: 10
 | 
				
			||||||
    ignoreSleeping: true
 | 
					    ignoreSleeping: true
 | 
				
			||||||
    maxAFKTime: 10m #in minutes
 | 
					    maxAFKTime: 10m #in minutes
 | 
				
			||||||
 | 
					    movePenalty: 10m
 | 
				
			||||||
 | 
					    moveProtection: true
 | 
				
			||||||
    openChest: true
 | 
					    openChest: true
 | 
				
			||||||
    preventInteractionBlocks: ['wooden_door', 'iron_door_block']
 | 
					    preventInteractionBlocks: ['wooden_door', 'iron_door_block']
 | 
				
			||||||
    preventInteractionBlocksPenalty: 5m
 | 
					    preventInteractionBlocksPenalty: 5m
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ language:
 | 
				
			|||||||
    croptrampling: 'trampling crops'
 | 
					    croptrampling: 'trampling crops'
 | 
				
			||||||
    interactionBlocks: 'interacting with a block'
 | 
					    interactionBlocks: 'interacting with a block'
 | 
				
			||||||
    interactionItems: 'interacting with an item'
 | 
					    interactionItems: 'interacting with an item'
 | 
				
			||||||
 | 
					    moving: 'trying to escape'
 | 
				
			||||||
  general:
 | 
					  general:
 | 
				
			||||||
    alljails: 'all the jails'
 | 
					    alljails: 'all the jails'
 | 
				
			||||||
    cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
 | 
					    cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
 | 
				
			||||||
@@ -36,7 +37,7 @@ language:
 | 
				
			|||||||
    notjailed: '&c%0% is not jailed.'
 | 
					    notjailed: '&c%0% is not jailed.'
 | 
				
			||||||
    offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.'
 | 
					    offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.'
 | 
				
			||||||
    onlinejail: '&2%0% was jailed for %1% minutes.'
 | 
					    onlinejail: '&2%0% was jailed for %1% minutes.'
 | 
				
			||||||
    protectionmessage: '&c%0% minutes has been added to your time for %1%.'
 | 
					    protectionmessage: '&c%0% minutes have been added to your time for %1%.'
 | 
				
			||||||
    protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
 | 
					    protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
 | 
				
			||||||
    suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
 | 
					    suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
 | 
				
			||||||
    unjailed: '&2You have been released! Please respect the server rules.'
 | 
					    unjailed: '&2You have been released! Please respect the server rules.'
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user