3
0
Fork 0

Fixed some bugs and added material to regions

This commit is contained in:
thomas 2021-09-13 09:40:37 +02:00
parent 06b579ee27
commit 4d0f53485b
21 changed files with 139 additions and 18 deletions

View file

@ -1,21 +1,34 @@
package nl.iobyte.themepark.api.attraction.objects; package nl.iobyte.themepark.api.attraction.objects;
import com.cryptomorin.xseries.XMaterial;
import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.ThemePark;
import nl.iobyte.themepark.api.config.objects.Configuration; 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 nl.iobyte.themepark.api.event.region.RegionNameChangeEvent;
import org.bukkit.Material;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Optional;
public class Region { public class Region {
private final String id; private final String id;
private String name; private String name;
private transient Material material;
private transient final Configuration configuration; private transient final Configuration configuration;
private final LinkedHashMap<String, Attraction> attractions = new LinkedHashMap<>(); private final LinkedHashMap<String, Attraction> attractions = new LinkedHashMap<>();
public Region(String id, String name) { public Region(String id, String name) {
this.id = id; this.id = id;
this.name = name; 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); 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 * Get Map with Attractions
* @return LinkedHashMap<String, Attraction> * @return LinkedHashMap<String, Attraction>

View file

@ -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<Material> {
public RegionMaterialChangeEvent(Region region, Material old, Material current) {
super(region, old, current);
}
}

View file

@ -93,9 +93,10 @@ public class StatusDataLoader implements IDataLoader {
//Load regions //Load regions
for(String id : section.getKeys(false)) { 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"); 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); attractionService.addRegion(region);
loadAttractions(api, region); //try loading Attractions for Region loadAttractions(api, region); //try loading Attractions for Region
} }

View file

@ -117,6 +117,7 @@ public class MainMenu {
switch (action.toUpperCase()) { switch (action.toUpperCase()) {
case "COMMAND": case "COMMAND":
case "BUNGEE_COMMAND":
return new CommandMenuHandler(manager.getString(StorageLocation.MENU, path+".command")); return new CommandMenuHandler(manager.getString(StorageLocation.MENU, path+".command"));
case "JSON_MESSAGE": case "JSON_MESSAGE":
return new JsonMessageMenuHandler(manager.getString(StorageLocation.MENU, path+".message")); return new JsonMessageMenuHandler(manager.getString(StorageLocation.MENU, path+".message"));

View file

@ -229,7 +229,7 @@ public class StatusMenu {
* @return ItemStack * @return ItemStack
*/ */
private static ItemStack getRegion(Region region) { private static ItemStack getRegion(Region region) {
ItemBuilder builder = new ItemBuilder(Material.NAME_TAG); ItemBuilder builder = new ItemBuilder(region.getMaterial());
builder.setName(region.getName()); builder.setName(region.getName());
return builder.getItem(); return builder.getItem();

View file

@ -12,8 +12,8 @@ public class CommandMenuHandler implements IActionHandler {
private final String command; private final String command;
public CommandMenuHandler(String command) { public CommandMenuHandler(String command) {
if(command.startsWith("/")) if(!command.startsWith("/"))
command = command.replaceFirst("/", ""); command = "/"+command;
this.command = command; this.command = command;
} }
@ -28,7 +28,7 @@ public class CommandMenuHandler implements IActionHandler {
public void execute(Player player) { public void execute(Player player) {
player.closeInventory(); player.closeInventory();
Bukkit.dispatchCommand(player, command); player.chat(command);
} }
} }

View file

@ -27,8 +27,12 @@ public class StatusSign {
public void update() { public void update() {
Status status = attraction.getStatus(); Status status = attraction.getStatus();
boolean b = location.getChunk().isLoaded();
if(!b)
location.getChunk().load(true);
if(!location.getChunk().isLoaded()) if(!location.getChunk().isLoaded())
location.getChunk().load(); return;
if(!(location.getBlock().getState() instanceof Sign)) { if(!(location.getBlock().getState() instanceof Sign)) {
ThemePark.getInstance().getAPI().getSignManager().removeSign(this); ThemePark.getInstance().getAPI().getSignManager().removeSign(this);
@ -39,6 +43,9 @@ public class StatusSign {
sign.setLine(1, Text.color(attraction.getName())); sign.setLine(1, Text.color(attraction.getName()));
sign.setLine(2, Text.color(status.getColor()+status.getName())); sign.setLine(2, Text.color(status.getColor()+status.getName()));
sign.update(); sign.update();
if(!b)
location.getChunk().unload();
} }
} }

View file

@ -22,6 +22,6 @@ public class AttractionCoverCommand extends SubCommand {
Attraction attraction = (Attraction) list.get(0); Attraction attraction = (Attraction) list.get(0);
String url = (String) list.get(1); String url = (String) list.get(1);
attraction.setCover(url); 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()));
} }
} }

View file

@ -22,7 +22,7 @@ public class AttractionLocationCommand extends SubCommand {
Attraction attraction = (Attraction) list.get(0); Attraction attraction = (Attraction) list.get(0);
Player player = (Player) sender.getOriginal(); Player player = (Player) sender.getOriginal();
attraction.setLocation(player.getLocation()); 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()));
} }
} }

View file

@ -22,7 +22,7 @@ public class AttractionNameCommand extends SubCommand {
Attraction attraction = (Attraction) list.get(0); Attraction attraction = (Attraction) list.get(0);
String name = (String) list.get(1); String name = (String) list.get(1);
attraction.setName(name); 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()));
} }
} }

View file

@ -23,7 +23,7 @@ public class AttractionRegionCommand extends SubCommand {
Attraction attraction = (Attraction) list.get(0); Attraction attraction = (Attraction) list.get(0);
Region region = (Region) list.get(1); Region region = (Region) list.get(1);
attraction.setRegionID(region.getID()); 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()));
} }
} }

View file

@ -20,7 +20,7 @@ public class AttractionRemoveCommand extends SubCommand {
public void onCommand(ICommandExecutor sender, List<Object> list, int i) { public void onCommand(ICommandExecutor sender, List<Object> list, int i) {
Attraction attraction = (Attraction) list.get(0); Attraction attraction = (Attraction) list.get(0);
ThemePark.getInstance().getAPI().getAttractionService().removeAttraction(attraction.getID()); 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()));
} }
} }

View file

@ -37,7 +37,7 @@ public class AttractionStatusCommand extends SubCommand {
return; return;
attraction.setStatus(status); 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()));
} }
); );
} }

View file

@ -8,6 +8,7 @@ public class RegionCommands {
factory.addSubCommand(new RegionListCommand(factory.getName())) factory.addSubCommand(new RegionListCommand(factory.getName()))
.addSubCommand(new RegionCreateCommand(factory.getName())) .addSubCommand(new RegionCreateCommand(factory.getName()))
.addSubCommand(new RegionNameCommand(factory.getName())) .addSubCommand(new RegionNameCommand(factory.getName()))
.addSubCommand(new RegionMaterialCommand(factory.getName()))
.addSubCommand(new RegionRemoveCommand(factory.getName())); .addSubCommand(new RegionRemoveCommand(factory.getName()));
} }

View file

@ -1,11 +1,13 @@
package nl.iobyte.themepark.commands.subcommands.region; package nl.iobyte.themepark.commands.subcommands.region;
import com.cryptomorin.xseries.XMaterial;
import nl.iobyte.commandapi.arguments.MessageArgument; import nl.iobyte.commandapi.arguments.MessageArgument;
import nl.iobyte.commandapi.interfaces.ICommandExecutor; import nl.iobyte.commandapi.interfaces.ICommandExecutor;
import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.commandapi.objects.SubCommand;
import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.ThemePark;
import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.attraction.objects.Region;
import nl.iobyte.themepark.api.message.Text; import nl.iobyte.themepark.api.message.Text;
import nl.iobyte.themepark.commands.arguments.MaterialArgument;
import nl.iobyte.themepark.commands.arguments.NoRegionArgument; import nl.iobyte.themepark.commands.arguments.NoRegionArgument;
import java.util.List; import java.util.List;
@ -18,17 +20,26 @@ public class RegionCreateCommand extends SubCommand {
addSyntax("/"+cmd+" region create <id> <name>") addSyntax("/"+cmd+" region create <id> <name>")
.addArgument(new NoRegionArgument()) .addArgument(new NoRegionArgument())
.addArgument(new MessageArgument()); .addArgument(new MessageArgument());
addSyntax("/"+cmd+" region create <id> <name> <material>")
.addArgument(new NoRegionArgument())
.addArgument(new MessageArgument())
.addArgument(new MaterialArgument());
} }
public void onCommand(ICommandExecutor sender, List<Object> list, int i) { public void onCommand(ICommandExecutor sender, List<Object> list, int i) {
String id = (String) list.get(0); String id = (String) list.get(0);
String name = (String) list.get(1); 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( ThemePark.getInstance().getAPI().getAttractionService().addRegion(new Region(
id, 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));
} }
} }

View file

@ -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 <id> <material>")
.addArgument(new RegionArgument())
.addArgument(new MaterialArgument());
}
public void onCommand(ICommandExecutor sender, List<Object> 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()));
}
}

View file

@ -22,7 +22,7 @@ public class RegionNameCommand extends SubCommand {
Region region = (Region) list.get(0); Region region = (Region) list.get(0);
String name = (String) list.get(1); String name = (String) list.get(1);
region.setName(name); 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()));
} }
} }

View file

@ -20,7 +20,7 @@ public class RegionRemoveCommand extends SubCommand {
public void onCommand(ICommandExecutor sender, List<Object> list, int i) { public void onCommand(ICommandExecutor sender, List<Object> list, int i) {
Region region = (Region) list.get(0); Region region = (Region) list.get(0);
ThemePark.getInstance().getAPI().getAttractionService().removeRegion(region.getID()); 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()));
} }
} }

View file

@ -36,7 +36,7 @@ public class RideCountAddCommand extends SubCommand {
); );
sender.sendMessage(Text.color( 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"
)); ));
} }

View file

@ -32,7 +32,7 @@ public class RideCountGetCommand extends SubCommand {
); );
sender.sendMessage(Text.color( 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"
)); ));
} }

View file

@ -4,6 +4,7 @@ import nl.iobyte.themepark.ThemePark;
import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.attraction.objects.Region;
import nl.iobyte.themepark.api.config.enums.StorageLocation; import nl.iobyte.themepark.api.config.enums.StorageLocation;
import nl.iobyte.themepark.api.event.region.RegionCreateEvent; 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.RegionNameChangeEvent;
import nl.iobyte.themepark.api.event.region.RegionRemoveEvent; import nl.iobyte.themepark.api.event.region.RegionRemoveEvent;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -22,6 +23,11 @@ public class RegionListener implements Listener {
"regions."+region.getID()+".name", "regions."+region.getID()+".name",
region.getName() region.getName()
); );
ThemePark.getInstance().getAPI().getConfigurationManager().set(
StorageLocation.REGIONS,
"regions."+region.getID()+".material",
region.getMaterial().toString()
);
//Update Menu //Update Menu
ThemePark.getInstance().getAPI().getMenuService().getStatusMenu().load(); 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 @EventHandler
public void onRemove(RegionRemoveEvent e) { public void onRemove(RegionRemoveEvent e) {
Region region = e.getRegion(); Region region = e.getRegion();