First attempt at getting the signs of cells to display information #31
The variables possible are: * %player% - the player's last known name * %uuid% - the player's uuid, or what can fit on a sign * %reason% - the reason the player was jailed * %jailer% - the person/thing who jailed this player * %afktime% - the amount of time the player has been afk * %timeinminutes% - the amount of remaining time the player has in minutes If the player is jailed forever, then it pulls from the language file `jailedforeversign` property.
This commit is contained in:
parent
24c6d31742
commit
81da8ddb59
@ -15,6 +15,7 @@ import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.legacy.LegacyManager;
|
||||
import com.graywolf336.jail.listeners.BlockListener;
|
||||
import com.graywolf336.jail.listeners.CacheListener;
|
||||
import com.graywolf336.jail.listeners.CellSignListener;
|
||||
import com.graywolf336.jail.listeners.EntityListener;
|
||||
import com.graywolf336.jail.listeners.HandCuffListener;
|
||||
import com.graywolf336.jail.listeners.JailingListener;
|
||||
@ -87,6 +88,7 @@ public class JailMain extends JavaPlugin {
|
||||
PluginManager plm = this.getServer().getPluginManager();
|
||||
plm.registerEvents(new BlockListener(this), this);
|
||||
plm.registerEvents(new CacheListener(this), this);
|
||||
plm.registerEvents(new CellSignListener(this), this);
|
||||
plm.registerEvents(new EntityListener(this), this);
|
||||
plm.registerEvents(new HandCuffListener(this), this);
|
||||
plm.registerEvents(new JailingListener(this), this);
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
/**
|
||||
* Provides a variety of methods, static, that are used throughout the plugin.
|
||||
@ -96,6 +97,23 @@ public class Util {
|
||||
return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1");
|
||||
}
|
||||
|
||||
/** Returns a message with all the possible variables replaced. */
|
||||
public static String replaceAllVariables(Prisoner p, String msg) {
|
||||
msg = msg.replaceAll("%player%", p.getLastKnownName());
|
||||
msg = msg.replaceAll("%uuid%", p.getUUID().toString());
|
||||
msg = msg.replaceAll("%reason%", p.getReason());
|
||||
msg = msg.replaceAll("%jailer", p.getJailer());
|
||||
msg = msg.replaceAll("%afktime%", TimeUnit.MILLISECONDS.toMinutes(p.getAFKTime()) + "m");
|
||||
|
||||
if(p.getRemainingTime() >= 0) {
|
||||
msg = msg.replaceAll("%timeinminutes%", String.valueOf(p.getRemainingTimeInMinutes()));
|
||||
}else {
|
||||
msg = msg.replaceAll("%timeinminutes%", Lang.JAILEDFOREVERSIGN.get());
|
||||
}
|
||||
|
||||
return getColorfulMessage(msg);
|
||||
}
|
||||
|
||||
/** Returns the wand used throughout the different creation steps. */
|
||||
public static ItemStack getWand() {
|
||||
ItemStack wand = new ItemStack(Material.WOOD_SWORD);
|
||||
@ -139,16 +157,16 @@ public class Util {
|
||||
if (match.matches()) {
|
||||
String units = match.group(2);
|
||||
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.SECONDS);
|
||||
t = TimeUnit.MILLISECONDS.toSeconds(Long.valueOf(match.group(1)));
|
||||
else if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units) || "m".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.MINUTES);
|
||||
t = TimeUnit.MILLISECONDS.toMinutes(Long.valueOf(match.group(1)));
|
||||
else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.HOURS);
|
||||
t = TimeUnit.MILLISECONDS.toHours(Long.valueOf(match.group(1)));
|
||||
else if ("days".equals(units) || "day".equals(units) || "d".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.DAYS);
|
||||
t = TimeUnit.MILLISECONDS.toDays(Long.valueOf(match.group(1)));
|
||||
else {
|
||||
try {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(time), TimeUnit.MINUTES);
|
||||
t = TimeUnit.MILLISECONDS.toMinutes(Long.parseLong(time));
|
||||
}catch(NumberFormatException e) {
|
||||
throw new Exception("Invalid format.");
|
||||
}
|
||||
|
@ -73,6 +73,11 @@ public class Cell {
|
||||
return this.signs;
|
||||
}
|
||||
|
||||
/** Checks if there are any signs for this cell. */
|
||||
public boolean hasSigns() {
|
||||
return !this.signs.isEmpty();
|
||||
}
|
||||
|
||||
/** Returns the entire list of signs in a string. */
|
||||
public String getSignString() {
|
||||
String r = "";
|
||||
|
@ -112,7 +112,7 @@ public class Prisoner {
|
||||
|
||||
/** Gets the remaining time the prisoner has in minutes. */
|
||||
public long getRemainingTimeInMinutes() {
|
||||
return TimeUnit.MINUTES.convert(time, TimeUnit.MILLISECONDS);
|
||||
return TimeUnit.MILLISECONDS.toMinutes(time);
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prison has in minutes except only in int format. */
|
||||
|
@ -125,10 +125,14 @@ public enum Lang {
|
||||
// General section, used by different parts
|
||||
/** Part message of any messages which require 'all the jails' or such. */
|
||||
ALLJAILS("general"),
|
||||
/** The one line on signs when the cell is empty. */
|
||||
CELLEMPTYSIGN("general"),
|
||||
/** The message sent to the sender whenever they try to remove a cell but was unsuccessful due to a prisoner. */
|
||||
CELLREMOVALUNSUCCESSFUL("general"),
|
||||
/** The message sent whenever a cell is successfully removed. */
|
||||
CELLREMOVED("general"),
|
||||
/** The line on a cell's sign when the prisoner is jailed forever. */
|
||||
JAILEDFOREVERSIGN("general"),
|
||||
/** The simple word jailing to be put in other parts. */
|
||||
JAILING("general"),
|
||||
/** The message sent to the sender when they try to remove a jail but there are still prisoners in there. */
|
||||
|
@ -9,6 +9,7 @@ public enum Settings {
|
||||
BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"),
|
||||
BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"),
|
||||
BLOCKPLACEWHITELIST("jailing.during.blockPlaceWhiteList"),
|
||||
CELLSIGNLINES("jailing.during.cellsign"),
|
||||
CLOTHINGENABLED("jailing.jail.clothing.enabled"),
|
||||
CLOTHINGHELMET("jailing.jail.clothing.helmet"),
|
||||
CLOTHINGCHEST("jailing.jail.clothing.chest"),
|
||||
|
@ -0,0 +1,122 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrisonerReleasedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerTimeChangeEvent;
|
||||
import com.graywolf336.jail.events.PrisonerTransferredEvent;
|
||||
|
||||
public class CellSignListener implements Listener {
|
||||
private String lineOne, lineTwo, lineThree, lineFour;
|
||||
|
||||
public CellSignListener(JailMain plugin) {
|
||||
List<String> lines = plugin.getConfig().getStringList(Settings.CELLSIGNLINES.getPath());
|
||||
lineOne = lines.get(0);
|
||||
lineTwo = lines.get(1);
|
||||
lineThree = lines.get(2);
|
||||
lineFour = lines.get(3);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void changeTheCellSigns(PrisonerTimeChangeEvent event) {
|
||||
if(event.hasCell() && event.getCell().hasSigns()) {
|
||||
HashSet<SimpleLocation> signs = event.getCell().getSigns();
|
||||
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
|
||||
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
|
||||
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
|
||||
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
|
||||
|
||||
for(SimpleLocation s : signs) {
|
||||
if(s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock().getState();
|
||||
sign.setLine(0, s1);
|
||||
sign.setLine(1, s2);
|
||||
sign.setLine(2, s3);
|
||||
sign.setLine(3, s4);
|
||||
sign.update();
|
||||
}else {
|
||||
//Remove the sign from the cell since it isn't
|
||||
//a valid sign
|
||||
event.getCell().getSigns().remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clearTheCellSigns(PrisonerReleasedEvent event) {
|
||||
if(event.hasCell() && event.getCell().hasSigns()) {
|
||||
HashSet<SimpleLocation> signs = event.getCell().getSigns();
|
||||
|
||||
for(SimpleLocation s : signs) {
|
||||
if(s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock().getState();
|
||||
sign.setLine(0, "");
|
||||
sign.setLine(1, Lang.CELLEMPTYSIGN.get());
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, "");
|
||||
sign.update();
|
||||
}else {
|
||||
//Remove the sign from the cell since it isn't
|
||||
//a valid sign
|
||||
event.getCell().getSigns().remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleSignsOnTransfer(PrisonerTransferredEvent event) {
|
||||
if(event.hasOriginalCell() && event.getOriginalCell().hasSigns()) {
|
||||
HashSet<SimpleLocation> signs = event.getOriginalCell().getSigns();
|
||||
|
||||
for(SimpleLocation s : signs) {
|
||||
if(s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock().getState();
|
||||
sign.setLine(0, "");
|
||||
sign.setLine(1, Lang.CELLEMPTYSIGN.get());
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, "");
|
||||
sign.update();
|
||||
}else {
|
||||
//Remove the sign from the cell since it isn't
|
||||
//a valid sign
|
||||
event.getOriginalCell().getSigns().remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(event.hasTargetCell() && event.getTargetCell().hasSigns()) {
|
||||
HashSet<SimpleLocation> signs = event.getTargetCell().getSigns();
|
||||
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
|
||||
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
|
||||
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
|
||||
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
|
||||
|
||||
for(SimpleLocation s : signs) {
|
||||
if(s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock().getState();
|
||||
sign.setLine(0, s1);
|
||||
sign.setLine(1, s2);
|
||||
sign.setLine(2, s3);
|
||||
sign.setLine(3, s4);
|
||||
sign.update();
|
||||
}else {
|
||||
//Remove the sign from the cell since it isn't
|
||||
//a valid sign
|
||||
event.getTargetCell().getSigns().remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -14,6 +15,7 @@ import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.CreationPlayer;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
/**
|
||||
* Class for stepping a player through the Cell creation process, instance is stored in {@link JailManager}.
|
||||
@ -93,6 +95,15 @@ public class CellCreationSteps {
|
||||
private void secondStep(CreationPlayer cp, Player player, Block block) {
|
||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
|
||||
cp.addSign(new SimpleLocation(block.getLocation()));
|
||||
|
||||
//Set the sign's first text
|
||||
Sign sign = (Sign) block.getState();
|
||||
sign.setLine(0, "");
|
||||
sign.setLine(1, Lang.CELLEMPTYSIGN.get());
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, "");
|
||||
sign.update();
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + "Sign added, if you want to select another go ahead otherwise right click on any non-sign block.");
|
||||
}else {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (chest) ----------");
|
||||
|
@ -24,6 +24,11 @@ jailing:
|
||||
blockPlacePenalty: 5m
|
||||
blockPlaceProtection: true
|
||||
blockPlaceWhiteList: ['crops', 'carrot', 'potato'] # these blocks can be placed at any time by prisoners
|
||||
cellsign:
|
||||
- '%player%'
|
||||
- '%timeinminutes% mins'
|
||||
- 'with a reason'
|
||||
- '%reason%'
|
||||
commandPenalty: 5m
|
||||
commandProtection: true
|
||||
commandWhitelist: ['/ping', '/list', '/jail status', '/jail pay']
|
||||
|
@ -14,8 +14,10 @@ language:
|
||||
start: "&cPlease type '&b/jail confirm&c' to confirm we should continue."
|
||||
general:
|
||||
alljails: 'all the jails'
|
||||
cellemptysign: 'Empty cell'
|
||||
cellremovalunsuccessful: '&cThe removal of cell %0% from jail %1% was unsuccessful because there is a prisoner in there still. Release or transfer before trying to remove the cell again.'
|
||||
cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
|
||||
jailedforeversign: '&cfor life'
|
||||
jailing: '&9jailing'
|
||||
jailremovalunsuccessful: '&cThe removal of the jail %0% was unsuccessful because there are prisoners in there, please release or transfer them first.'
|
||||
jailremoved: '&9Jail %0% has been successfully deleted.'
|
||||
|
Loading…
Reference in New Issue
Block a user