Search in sources :

Example 1 with SoliniaZone

use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.

the class SoliniaZoneFactory method Create.

public static SoliniaZone Create(String zonename, int x, int y, int z, boolean operatorCreated) throws CoreStateInitException, SoliniaZoneCreationException {
    if (StateManager.getInstance().getConfigurationManager().getZone(zonename.toUpperCase()) != null)
        throw new SoliniaZoneCreationException("Zone already exists");
    SoliniaZone zone = new SoliniaZone();
    zone.setId(StateManager.getInstance().getConfigurationManager().getNextZoneId());
    zone.setName(zonename.toUpperCase());
    zone.setX(x);
    zone.setY(y);
    zone.setZ(z);
    zone.setOperatorCreated(operatorCreated);
    StateManager.getInstance().getConfigurationManager().addZone(zone);
    return zone;
}
Also used : SoliniaZone(com.solinia.solinia.Models.SoliniaZone) SoliniaZoneCreationException(com.solinia.solinia.Exceptions.SoliniaZoneCreationException)

Example 2 with SoliniaZone

use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.

the class CommandEditZone method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.editzone")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: zoneid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int zoneid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            SoliniaZone zone = StateManager.getInstance().getConfigurationManager().getZone(zoneid);
            if (zone != null) {
                zone.sendZoneSettingsToSender(sender);
            } else {
                sender.sendMessage("Zone ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: zoneid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (zoneid < 1) {
        sender.sendMessage("Invalid zoneid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getZone(zoneid) == null) {
            sender.sendMessage("Cannot locate zone id: " + zoneid);
            return false;
        }
        /*if (StateManager.getInstance().getConfigurationManager().getZone(zoneid).isOperatorCreated() && !sender.isOp())
			{
				sender.sendMessage("This zone was op created and you are not an op. Only ops can edit op zone items");
				return false;
			}*/
        StateManager.getInstance().getConfigurationManager().editZone(zoneid, setting, value);
        sender.sendMessage("Updating setting on Zone");
    } catch (InvalidZoneSettingException ne) {
        sender.sendMessage("Invalid zone setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : InvalidZoneSettingException(com.solinia.solinia.Exceptions.InvalidZoneSettingException) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) SoliniaZone(com.solinia.solinia.Models.SoliniaZone)

Example 3 with SoliniaZone

use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.

the class CommandCreateZone method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.createzone")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 4) {
        sender.sendMessage("Insufficient arguments: namenospaces x y z");
        return false;
    }
    String zonename = args[0].toUpperCase();
    int x = Integer.parseInt(args[1]);
    int y = Integer.parseInt(args[2]);
    int z = Integer.parseInt(args[3]);
    if (zonename.equals("")) {
        sender.sendMessage("Name of Zone cannot be null");
        return false;
    }
    try {
        SoliniaZone zone = SoliniaZoneFactory.Create(zonename, x, y, z, sender.isOp());
        sender.sendMessage("Created Zone: " + zone.getId());
    } catch (CoreStateInitException | SoliniaZoneCreationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) SoliniaZone(com.solinia.solinia.Models.SoliniaZone) SoliniaZoneCreationException(com.solinia.solinia.Exceptions.SoliniaZoneCreationException)

Example 4 with SoliniaZone

use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.

the class CoreState method setRandomHotzones.

public void setRandomHotzones() {
    currentHotZones.clear();
    try {
        int maxCheckSize = StateManager.getInstance().getConfigurationManager().getZones().size() * 4;
        int currentCount = 0;
        List<SoliniaZone> possibleHotZones = new ArrayList<SoliniaZone>();
        for (SoliniaZone zone : StateManager.getInstance().getConfigurationManager().getZones()) {
            if (!zone.isHotzone())
                continue;
            possibleHotZones.add(zone);
        }
        // if there isnt any just skip this
        if (possibleHotZones.size() < 1)
            return;
        // If only one, just always return it
        if (possibleHotZones.size() == 1) {
            currentHotZones.add(possibleHotZones.get(0).getId());
            return;
        }
        // Else try to pick two random ones
        while (currentHotZones.size() < 2) {
            if (currentCount > maxCheckSize)
                break;
            SoliniaZone zone = Utils.getRandomItemFromList(possibleHotZones);
            if (!zone.isHotzone())
                continue;
            if (currentHotZones.contains(zone.getId()))
                continue;
            System.out.println("Hotzone set to: " + zone.getName());
            currentHotZones.add(zone.getId());
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) SoliniaZone(com.solinia.solinia.Models.SoliniaZone)

Example 5 with SoliniaZone

use of com.solinia.solinia.Models.SoliniaZone in project solinia3-core by mixxit.

the class ChannelManager method sendHotzonesToDiscordChannel.

private void sendHotzonesToDiscordChannel(DiscordChannel discordChannel) {
    String list = "";
    String targetChannelId = getDefaultDiscordChannel();
    if (discordChannel.equals(DiscordChannel.ADMIN))
        targetChannelId = getAdminDiscordChannel();
    try {
        sendToDiscordMC(null, targetChannelId, "Current 100% bonus XP Hotzones are: ");
        for (SoliniaZone zone : StateManager.getInstance().getCurrentHotzones()) {
            sendToDiscordMC(null, targetChannelId, zone.getName() + ": " + zone.getX() + "," + zone.getY() + "," + zone.getZ());
        }
    } catch (Exception e) {
    // ignore it
    }
}
Also used : SoliniaZone(com.solinia.solinia.Models.SoliniaZone) EventException(org.bukkit.event.EventException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Aggregations

SoliniaZone (com.solinia.solinia.Models.SoliniaZone)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 Gson (com.google.gson.Gson)2 SoliniaZoneCreationException (com.solinia.solinia.Exceptions.SoliniaZoneCreationException)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 CommandSender (org.bukkit.command.CommandSender)2 Player (org.bukkit.entity.Player)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 InvalidZoneSettingException (com.solinia.solinia.Exceptions.InvalidZoneSettingException)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 List (java.util.List)1 EventException (org.bukkit.event.EventException)1