Fixed some bugs and added material to regions
This commit is contained in:
parent
06b579ee27
commit
4d0f53485b
21 changed files with 139 additions and 18 deletions
|
@ -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<String, Attraction> 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<String, Attraction>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class AttractionRemoveCommand extends SubCommand {
|
|||
public void onCommand(ICommandExecutor sender, List<Object> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <id> <name>")
|
||||
.addArgument(new NoRegionArgument())
|
||||
.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) {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class RegionRemoveCommand extends SubCommand {
|
|||
public void onCommand(ICommandExecutor sender, List<Object> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Reference in a new issue