diff --git a/src/main/java/nl/iobyte/themepark/api/attraction/objects/Region.java b/src/main/java/nl/iobyte/themepark/api/attraction/objects/Region.java index e9c2636..3e2ded1 100644 --- a/src/main/java/nl/iobyte/themepark/api/attraction/objects/Region.java +++ b/src/main/java/nl/iobyte/themepark/api/attraction/objects/Region.java @@ -1,21 +1,34 @@ package nl.iobyte.themepark.api.attraction.objects; +import com.cryptomorin.xseries.XMaterial; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.config.objects.Configuration; +import nl.iobyte.themepark.api.event.region.RegionMaterialChangeEvent; import nl.iobyte.themepark.api.event.region.RegionNameChangeEvent; +import org.bukkit.Material; import java.util.LinkedHashMap; +import java.util.Optional; public class Region { private final String id; private String name; + private transient Material material; private transient final Configuration configuration; private final LinkedHashMap attractions = new LinkedHashMap<>(); public Region(String id, String name) { this.id = id; this.name = name; + this.material = XMaterial.matchXMaterial("NAME_TAG").orElse(XMaterial.NAME_TAG).parseMaterial(); + configuration = new Configuration(ThemePark.getInstance(), "attractions/"+id+".yml", false); + } + + public Region(String id, String name, Material material) { + this.id = id; + this.name = name; + this.material = Optional.ofNullable(material).orElse(XMaterial.NAME_TAG.parseMaterial()); configuration = new Configuration(ThemePark.getInstance(), "attractions/"+id+".yml", false); } @@ -49,6 +62,28 @@ public class Region { )); } + /** + * Get Material of Region + * @return Material + */ + public Material getMaterial() { + return material; + } + + /** + * Set Material of Region + * @param material Material + */ + public void setMaterial(Material material) { + Material old = this.material; + this.material = material; + ThemePark.getInstance().getAPI().getEventDispatcher().call(new RegionMaterialChangeEvent( + this, + old, + material + )); + } + /** * Get Map with Attractions * @return LinkedHashMap diff --git a/src/main/java/nl/iobyte/themepark/api/event/region/RegionMaterialChangeEvent.java b/src/main/java/nl/iobyte/themepark/api/event/region/RegionMaterialChangeEvent.java new file mode 100644 index 0000000..28a94a6 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/event/region/RegionMaterialChangeEvent.java @@ -0,0 +1,13 @@ +package nl.iobyte.themepark.api.event.region; + +import nl.iobyte.themepark.api.attraction.objects.Region; +import nl.iobyte.themepark.api.event.objects.RegionEvent; +import org.bukkit.Material; + +public class RegionMaterialChangeEvent extends RegionEvent { + + public RegionMaterialChangeEvent(Region region, Material old, Material current) { + super(region, old, current); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java b/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java index 9149fba..b40204d 100644 --- a/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java +++ b/src/main/java/nl/iobyte/themepark/api/load/objects/StatusDataLoader.java @@ -93,9 +93,10 @@ public class StatusDataLoader implements IDataLoader { //Load regions for(String id : section.getKeys(false)) { + XMaterial material = XMaterial.matchXMaterial(manager.getString(StorageLocation.REGIONS, "regions."+id+".material")).orElse(XMaterial.NAME_TAG); String name = manager.getString(StorageLocation.REGIONS, "regions."+id+".name"); - Region region = new Region(id, name); + Region region = new Region(id, name, material.parseMaterial()); attractionService.addRegion(region); loadAttractions(api, region); //try loading Attractions for Region } diff --git a/src/main/java/nl/iobyte/themepark/api/menu/objects/MainMenu.java b/src/main/java/nl/iobyte/themepark/api/menu/objects/MainMenu.java index 0aec19f..cb22c52 100644 --- a/src/main/java/nl/iobyte/themepark/api/menu/objects/MainMenu.java +++ b/src/main/java/nl/iobyte/themepark/api/menu/objects/MainMenu.java @@ -117,6 +117,7 @@ public class MainMenu { switch (action.toUpperCase()) { case "COMMAND": + case "BUNGEE_COMMAND": return new CommandMenuHandler(manager.getString(StorageLocation.MENU, path+".command")); case "JSON_MESSAGE": return new JsonMessageMenuHandler(manager.getString(StorageLocation.MENU, path+".message")); diff --git a/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java b/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java index 69bf20a..d6ce88c 100644 --- a/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java +++ b/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java @@ -229,7 +229,7 @@ public class StatusMenu { * @return ItemStack */ private static ItemStack getRegion(Region region) { - ItemBuilder builder = new ItemBuilder(Material.NAME_TAG); + ItemBuilder builder = new ItemBuilder(region.getMaterial()); builder.setName(region.getName()); return builder.getItem(); diff --git a/src/main/java/nl/iobyte/themepark/api/menu/objects/handlers/CommandMenuHandler.java b/src/main/java/nl/iobyte/themepark/api/menu/objects/handlers/CommandMenuHandler.java index 6c47e02..fb1f088 100644 --- a/src/main/java/nl/iobyte/themepark/api/menu/objects/handlers/CommandMenuHandler.java +++ b/src/main/java/nl/iobyte/themepark/api/menu/objects/handlers/CommandMenuHandler.java @@ -12,8 +12,8 @@ public class CommandMenuHandler implements IActionHandler { private final String command; public CommandMenuHandler(String command) { - if(command.startsWith("/")) - command = command.replaceFirst("/", ""); + if(!command.startsWith("/")) + command = "/"+command; this.command = command; } @@ -28,7 +28,7 @@ public class CommandMenuHandler implements IActionHandler { public void execute(Player player) { player.closeInventory(); - Bukkit.dispatchCommand(player, command); + player.chat(command); } } diff --git a/src/main/java/nl/iobyte/themepark/api/sign/objects/StatusSign.java b/src/main/java/nl/iobyte/themepark/api/sign/objects/StatusSign.java index c41ddb3..85d9e52 100644 --- a/src/main/java/nl/iobyte/themepark/api/sign/objects/StatusSign.java +++ b/src/main/java/nl/iobyte/themepark/api/sign/objects/StatusSign.java @@ -27,8 +27,12 @@ public class StatusSign { public void update() { Status status = attraction.getStatus(); + boolean b = location.getChunk().isLoaded(); + if(!b) + location.getChunk().load(true); + if(!location.getChunk().isLoaded()) - location.getChunk().load(); + return; if(!(location.getBlock().getState() instanceof Sign)) { ThemePark.getInstance().getAPI().getSignManager().removeSign(this); @@ -39,6 +43,9 @@ public class StatusSign { sign.setLine(1, Text.color(attraction.getName())); sign.setLine(2, Text.color(status.getColor()+status.getName())); sign.update(); + + if(!b) + location.getChunk().unload(); } } \ No newline at end of file diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java index 470301c..b27c767 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionCoverCommand.java @@ -22,6 +22,6 @@ public class AttractionCoverCommand extends SubCommand { Attraction attraction = (Attraction) list.get(0); String url = (String) list.get(1); attraction.setCover(url); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the cover of attraction &f"+attraction.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the cover of attraction &f"+attraction.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java index c080660..3e7ab78 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionLocationCommand.java @@ -22,7 +22,7 @@ public class AttractionLocationCommand extends SubCommand { Attraction attraction = (Attraction) list.get(0); Player player = (Player) sender.getOriginal(); attraction.setLocation(player.getLocation()); - player.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the location of attraction &f"+attraction.getID())); + player.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the location of attraction &f"+attraction.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java index 384cb72..8346f4f 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionNameCommand.java @@ -22,7 +22,7 @@ public class AttractionNameCommand extends SubCommand { Attraction attraction = (Attraction) list.get(0); String name = (String) list.get(1); attraction.setName(name); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the name of attraction &f"+attraction.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the name of attraction &f"+attraction.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java index 7b70d07..965fd8e 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRegionCommand.java @@ -23,7 +23,7 @@ public class AttractionRegionCommand extends SubCommand { Attraction attraction = (Attraction) list.get(0); Region region = (Region) list.get(1); attraction.setRegionID(region.getID()); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the region of attraction &f"+attraction.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the region of attraction &f"+attraction.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java index ac2be97..d641f18 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionRemoveCommand.java @@ -20,7 +20,7 @@ public class AttractionRemoveCommand extends SubCommand { public void onCommand(ICommandExecutor sender, List list, int i) { Attraction attraction = (Attraction) list.get(0); ThemePark.getInstance().getAPI().getAttractionService().removeAttraction(attraction.getID()); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully removed attraction &f"+attraction.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully removed attraction &f"+attraction.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java index 491e2b9..edff53c 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/attraction/AttractionStatusCommand.java @@ -37,7 +37,7 @@ public class AttractionStatusCommand extends SubCommand { return; attraction.setStatus(status); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the status of attraction &f"+attraction.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the status of attraction &f"+attraction.getName())); } ); } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java index e2319df..78faa4c 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCommands.java @@ -8,6 +8,7 @@ public class RegionCommands { factory.addSubCommand(new RegionListCommand(factory.getName())) .addSubCommand(new RegionCreateCommand(factory.getName())) .addSubCommand(new RegionNameCommand(factory.getName())) + .addSubCommand(new RegionMaterialCommand(factory.getName())) .addSubCommand(new RegionRemoveCommand(factory.getName())); } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java index 5e9db6e..d83be4f 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionCreateCommand.java @@ -1,11 +1,13 @@ package nl.iobyte.themepark.commands.subcommands.region; +import com.cryptomorin.xseries.XMaterial; import nl.iobyte.commandapi.arguments.MessageArgument; import nl.iobyte.commandapi.interfaces.ICommandExecutor; import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.message.Text; +import nl.iobyte.themepark.commands.arguments.MaterialArgument; import nl.iobyte.themepark.commands.arguments.NoRegionArgument; import java.util.List; @@ -18,17 +20,26 @@ public class RegionCreateCommand extends SubCommand { addSyntax("/"+cmd+" region create ") .addArgument(new NoRegionArgument()) .addArgument(new MessageArgument()); + + addSyntax("/"+cmd+" region create ") + .addArgument(new NoRegionArgument()) + .addArgument(new MessageArgument()) + .addArgument(new MaterialArgument()); } public void onCommand(ICommandExecutor sender, List list, int i) { String id = (String) list.get(0); String name = (String) list.get(1); + XMaterial material = XMaterial.NAME_TAG; + if(i != 0) + material = (XMaterial) list.get(2); ThemePark.getInstance().getAPI().getAttractionService().addRegion(new Region( id, - name + name, + material.parseMaterial() )); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully created region &f"+id)); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully created region &f"+name)); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionMaterialCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionMaterialCommand.java new file mode 100644 index 0000000..ecf9784 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionMaterialCommand.java @@ -0,0 +1,31 @@ +package nl.iobyte.themepark.commands.subcommands.region; + +import com.cryptomorin.xseries.XMaterial; +import nl.iobyte.commandapi.arguments.MessageArgument; +import nl.iobyte.commandapi.interfaces.ICommandExecutor; +import nl.iobyte.commandapi.objects.SubCommand; +import nl.iobyte.themepark.api.attraction.objects.Region; +import nl.iobyte.themepark.api.message.Text; +import nl.iobyte.themepark.commands.arguments.MaterialArgument; +import nl.iobyte.themepark.commands.arguments.RegionArgument; +import java.util.List; + +public class RegionMaterialCommand extends SubCommand { + + public RegionMaterialCommand(String cmd) { + super("themepark.admin", "region", "material"); + + addSyntax("/"+cmd+" region material ") + .addArgument(new RegionArgument()) + .addArgument(new MaterialArgument()); + } + + public void onCommand(ICommandExecutor sender, List list, int i) { + Region region = (Region) list.get(0); + XMaterial material = (XMaterial) list.get(1); + region.setMaterial(material.parseMaterial()); + + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the material of region &f"+region.getName())); + } + +} diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java index 8e3e6e5..c97b47a 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionNameCommand.java @@ -22,7 +22,7 @@ public class RegionNameCommand extends SubCommand { Region region = (Region) list.get(0); String name = (String) list.get(1); region.setName(name); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the name of region &f"+region.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully changed the name of region &f"+region.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java index e837335..445270d 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/region/RegionRemoveCommand.java @@ -20,7 +20,7 @@ public class RegionRemoveCommand extends SubCommand { public void onCommand(ICommandExecutor sender, List list, int i) { Region region = (Region) list.get(0); ThemePark.getInstance().getAPI().getAttractionService().removeRegion(region.getID()); - sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully removed region &f"+region.getID())); + sender.sendMessage(Text.color("&6&lThemePark &f➢ &aSuccessfully removed region &f"+region.getName())); } } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java index 86b4fbc..25fa0f1 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountAddCommand.java @@ -36,7 +36,7 @@ public class RideCountAddCommand extends SubCommand { ); sender.sendMessage(Text.color( - "&6&lThemePark &f➢ &aSuccessfully added count of: &6"+amount+"x &ato attraction: &f"+attraction.getID()+" &afor &6"+players.size()+" &aplayers" + "&6&lThemePark &f➢ &aSuccessfully added count of: &6"+amount+"x &ato attraction: &f"+attraction.getName()+" &afor &6"+players.size()+" &aplayers" )); } diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java index 67a202b..b124fd9 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/ridecount/RideCountGetCommand.java @@ -32,7 +32,7 @@ public class RideCountGetCommand extends SubCommand { ); sender.sendMessage(Text.color( - "&6&lThemePark &f➢ You have ridden attraction: &f"+attraction.getID()+" &ffor &6"+(count == null ? 0 : count.getCount())+"x" + "&6&lThemePark &f➢ You have ridden attraction: &f"+attraction.getName()+" &ffor &6"+(count == null ? 0 : count.getCount())+"x" )); } diff --git a/src/main/java/nl/iobyte/themepark/listeners/RegionListener.java b/src/main/java/nl/iobyte/themepark/listeners/RegionListener.java index fb3e8d3..4962d0e 100644 --- a/src/main/java/nl/iobyte/themepark/listeners/RegionListener.java +++ b/src/main/java/nl/iobyte/themepark/listeners/RegionListener.java @@ -4,6 +4,7 @@ import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.config.enums.StorageLocation; import nl.iobyte.themepark.api.event.region.RegionCreateEvent; +import nl.iobyte.themepark.api.event.region.RegionMaterialChangeEvent; import nl.iobyte.themepark.api.event.region.RegionNameChangeEvent; import nl.iobyte.themepark.api.event.region.RegionRemoveEvent; import org.bukkit.event.EventHandler; @@ -22,6 +23,11 @@ public class RegionListener implements Listener { "regions."+region.getID()+".name", region.getName() ); + ThemePark.getInstance().getAPI().getConfigurationManager().set( + StorageLocation.REGIONS, + "regions."+region.getID()+".material", + region.getMaterial().toString() + ); //Update Menu ThemePark.getInstance().getAPI().getMenuService().getStatusMenu().load(); @@ -62,6 +68,21 @@ public class RegionListener implements Listener { ); } + @EventHandler + public void onNameChange(RegionMaterialChangeEvent e) { + Region region = e.getRegion(); + + //Change Region name in config + ThemePark.getInstance().getAPI().getConfigurationManager().set( + StorageLocation.REGIONS, + "regions."+region.getID()+".material", + region.getMaterial().toString() + ); + + //Update Menu + ThemePark.getInstance().getAPI().getMenuService().getStatusMenu().updateRegion(region); + } + @EventHandler public void onRemove(RegionRemoveEvent e) { Region region = e.getRegion();