From b490df861e7cf712b8a15cd3d9141a74a503a7bb Mon Sep 17 00:00:00 2001 From: Charlie Date: Mon, 28 Jul 2014 09:37:04 -0400 Subject: [PATCH] Migration to Maven, removing buggy code In preparation for using sk89q's command framework --- .gitignore | 1 + README.md | 12 ++- pom.xml | 52 +++++++++++ .../ca/gibstick/discosheep/DiscoParty.java | 8 +- .../ca/gibstick/discosheep/DiscoSheep.java | 62 +++++++------ .../discosheep/DiscoSheepCommandExecutor.java | 42 ++++----- .../ca/gibstick/discosheep/GlobalEvents.java | 0 .../ca/gibstick/discosheep/PartyEvents.java | 0 src/main/resources/plugin.yml | 93 +++++++++++++++++++ 9 files changed, 214 insertions(+), 56 deletions(-) create mode 100644 .gitignore create mode 100644 pom.xml rename src/{ => main/java}/ca/gibstick/discosheep/DiscoParty.java (98%) rename src/{ => main/java}/ca/gibstick/discosheep/DiscoSheep.java (83%) rename src/{ => main/java}/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java (86%) rename src/{ => main/java}/ca/gibstick/discosheep/GlobalEvents.java (100%) rename src/{ => main/java}/ca/gibstick/discosheep/PartyEvents.java (100%) create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6f89c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ \ No newline at end of file diff --git a/README.md b/README.md index 11ff927..0446de3 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,18 @@ DiscoSheep A plugin for [Bukkit](http://bukkit.org/), the Minecraft server API. This is a from-scratch remake of the fabulous [DiscoSheep plugin](http://forums.bukkit.org/threads/inactive-fun-discosheep-v0-3-uninvited-guesssts-permissions-and-source-code-522.7106/) which spawns a dance party of sheep at your whim. +###DiscoFix### +An attempt to fix up DiscoSheep. No new big features. A short (non-binding) todo list: +* fix NPE for guests +* refactor command handling (use sk89q's framework) +* fix wifi, bluetooth, GPS (wipe dalvik x333) +* you tell me + +##A note on UUIDs## +DiscoSheep doesn't store anything after a party and getPlayer(name), and disco-party-on-join is handled by a permissions plugin. Thus, we don't need to worry about the migration to UUIDs. + ###Versions### -Tested up to CraftBukkit build 2918 (RB for 1.6.4 R2.0); can be built with Java 6. +Tested up to CraftBukkit build 2918 (RB for 1.6.4 R2.0); can be built with Java 7. ###[BukkitDev](http://dev.bukkit.org/bukkit-plugins/superdiscosheep/)### diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1bf4dfa --- /dev/null +++ b/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + ca.gibstick + DiscoSheep + 1.1.2 + jar + + + bukkit-repo + http://repo.bukkit.org/content/groups/public/ + + + + + org.bukkit + bukkit + provided + 1.7.9-R0.2 + + + + DiscoSheep + src/main/java + + + . + true + src/main/resources/ + + plugin.yml + + + + + + maven-compiler-plugin + 3.1 + + + -Xlint:deprecation + + + + + + + UTF-8 + 1.7 + 1.7 + + \ No newline at end of file diff --git a/src/ca/gibstick/discosheep/DiscoParty.java b/src/main/java/ca/gibstick/discosheep/DiscoParty.java similarity index 98% rename from src/ca/gibstick/discosheep/DiscoParty.java rename to src/main/java/ca/gibstick/discosheep/DiscoParty.java index 132e4a7..7cb2a5b 100644 --- a/src/ca/gibstick/discosheep/DiscoParty.java +++ b/src/main/java/ca/gibstick/discosheep/DiscoParty.java @@ -276,7 +276,7 @@ public class DiscoParty { } loc = player.getLocation(); - this.spawnFloor(world, new Location(world, loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())); + //this.spawnFloor(world, new Location(world, loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())); } void spawnSheep(World world, Location loc) { @@ -428,9 +428,9 @@ public class DiscoParty { } } - for (Block block : this.floorBlocks) { - this.randomizeFloor(block); - } + /* for (Block block : this.floorBlocks) { + this.randomizeFloor(block); + }*/ } diff --git a/src/ca/gibstick/discosheep/DiscoSheep.java b/src/main/java/ca/gibstick/discosheep/DiscoSheep.java similarity index 83% rename from src/ca/gibstick/discosheep/DiscoSheep.java rename to src/main/java/ca/gibstick/discosheep/DiscoSheep.java index 2cfb22c..9a7389f 100644 --- a/src/ca/gibstick/discosheep/DiscoSheep.java +++ b/src/main/java/ca/gibstick/discosheep/DiscoSheep.java @@ -25,7 +25,7 @@ public final class DiscoSheep extends JavaPlugin { static final String PERMISSION_SPAWNGUESTS = "discosheep.party.spawnguests"; static final String PERMISSION_TOGGLEPARTYONJOIN = "discosheep.admin.toggleonjoin"; static final String PERMISSION_LIGHTNING = "discosheep.party.lightning"; - static boolean partyOnJoin = true; + static boolean partyOnJoin = false; Map parties = new HashMap(); @Override @@ -48,22 +48,21 @@ public final class DiscoSheep extends JavaPlugin { * Iterate through all live entities and create default configuration values for them * excludes bosses and other mobs that throw NPE */ - for (EntityType ent : EntityType.values()) { - if (ent.isAlive() - && !ent.equals(EntityType.ENDER_DRAGON) - && !ent.equals(EntityType.WITHER) - && !ent.equals(EntityType.PIG_ZOMBIE) - && !ent.equals(EntityType.OCELOT) - && !ent.equals(EntityType.CAVE_SPIDER) - && !ent.equals(EntityType.MAGMA_CUBE) - && !ent.equals(EntityType.MUSHROOM_COW) - && !ent.equals(EntityType.IRON_GOLEM) - && !ent.equals(EntityType.PLAYER)) { - getConfig().addDefault("default.guests." + ent.toString(), 0); - getConfig().addDefault("max.guests." + ent.toString(), 0); - } - } - + /* for (EntityType ent : EntityType.values()) { + if (ent.isAlive() + && !ent.equals(EntityType.ENDER_DRAGON) + && !ent.equals(EntityType.WITHER) + && !ent.equals(EntityType.PIG_ZOMBIE) + && !ent.equals(EntityType.OCELOT) + && !ent.equals(EntityType.CAVE_SPIDER) + && !ent.equals(EntityType.MAGMA_CUBE) + && !ent.equals(EntityType.MUSHROOM_COW) + && !ent.equals(EntityType.IRON_GOLEM) + && !ent.equals(EntityType.PLAYER)) { + getConfig().addDefault("default.guests." + ent.toString(), 0); + getConfig().addDefault("max.guests." + ent.toString(), 0); + } + }*/ loadConfigFromDisk(); } @@ -82,13 +81,13 @@ public final class DiscoSheep extends JavaPlugin { DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration")); DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks"); - for (String key : getConfig().getConfigurationSection("default.guests").getKeys(false)) { - DiscoParty.getDefaultGuestNumbers().put(key, getConfig().getInt("default.guests." + key)); - } - - for (String key : getConfig().getConfigurationSection("max.guests").getKeys(false)) { - DiscoParty.getMaxGuestNumbers().put(key, getConfig().getInt("max.guests." + key)); - } + /* for (String key : getConfig().getConfigurationSection("default.guests").getKeys(false)) { + DiscoParty.getDefaultGuestNumbers().put(key, getConfig().getInt("default.guests." + key)); + } + + for (String key : getConfig().getConfigurationSection("max.guests").getKeys(false)) { + DiscoParty.getMaxGuestNumbers().put(key, getConfig().getInt("max.guests." + key)); + }*/ } @@ -104,9 +103,9 @@ public final class DiscoSheep extends JavaPlugin { getConfig().set("default.duration", toSeconds_i(DiscoParty.defaultDuration)); getConfig().set("default.period-ticks", DiscoParty.defaultPeriod); - for (Map.Entry entry : DiscoParty.getDefaultGuestNumbers().entrySet()) { - getConfig().set("default.guests." + entry.getKey(), entry.getValue()); - } + /* for (Map.Entry entry : DiscoParty.getDefaultGuestNumbers().entrySet()) { + getConfig().set("default.guests." + entry.getKey(), entry.getValue()); + }*/ saveConfig(); } @@ -176,8 +175,8 @@ public final class DiscoSheep extends JavaPlugin { + "-t : set the party duration in seconds\n" + "-p : set the number of ticks between each disco beat\n" + "-r : set radius of the area in which sheep can spawn\n" - + "-g : set spawns for other mobs" - + "-l: enables lightning" + //+ "-g : set spawns for other mobs\n" + + "-l: enables lightning\n" + "-fw: enables fireworks"); return true; } @@ -219,7 +218,10 @@ public final class DiscoSheep extends JavaPlugin { return noPermsMessage(sender, PERMISSION_RELOAD); } } - + + @SuppressWarnings( "deprecation" ) + // UUIDs not necessary since DiscoSheep only lasts for one session at most + // and permissions will handle onJoin DiscoSheep boolean partyOtherCommand(String[] players, CommandSender sender, DiscoParty party) { if (sender.hasPermission(PERMISSION_OTHER)) { Player p; diff --git a/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java b/src/main/java/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java similarity index 86% rename from src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java rename to src/main/java/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java index 72bdca7..f096ea0 100644 --- a/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java +++ b/src/main/java/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; public class DiscoSheepCommandExecutor implements CommandExecutor { - private DiscoSheep parent; + private final DiscoSheep parent; public DiscoSheepCommandExecutor(DiscoSheep parent) { this.parent = parent; @@ -147,26 +147,26 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { + DiscoParty.maxPeriod + "]"); return false; } - } else if (args[i].equalsIgnoreCase("-g")) { - if (!sender.hasPermission(DiscoSheep.PERMISSION_SPAWNGUESTS)) { - return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_SPAWNGUESTS); - } - - if (parseNextArg(args, i, "none")) { - return parent.clearGuests(mainParty); - } - - String[] guests = getNextArgs(args, i + 1); - int j = 0; - while (j < guests.length - 1) { - try { - mainParty.setGuestNumber(guests[j], getNextIntArg(guests, j)); - } catch (IllegalArgumentException e) { - sender.sendMessage(ChatColor.RED + "Invalid arguments: " + ChatColor.WHITE + guests[j] + ", " + guests[j + 1] - + ".\nEither a name typo or a number that is not within limits."); - } - j += 2; // skip over two arguments, since they come in pairs of entity-number - } +// } else if (args[i].equalsIgnoreCase("-g")) { +// if (!sender.hasPermission(DiscoSheep.PERMISSION_SPAWNGUESTS)) { +// return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_SPAWNGUESTS); +// } +// +// if (parseNextArg(args, i, "none")) { +// return parent.clearGuests(mainParty); +// } +// +// String[] guests = getNextArgs(args, i + 1); +// int j = 0; +// while (j < guests.length - 1) { +// try { +// mainParty.setGuestNumber(guests[j], getNextIntArg(guests, j)); +// } catch (IllegalArgumentException e) { +// sender.sendMessage(ChatColor.RED + "Invalid arguments: " + ChatColor.WHITE + guests[j] + ", " + guests[j + 1] +// + ".\nEither a name typo or a number that is not within limits."); +// } +// j += 2; // skip over two arguments, since they come in pairs of entity-number +// } } else if (args[i].equalsIgnoreCase("-l")) { if (!sender.hasPermission(DiscoSheep.PERMISSION_LIGHTNING)) { return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_LIGHTNING); diff --git a/src/ca/gibstick/discosheep/GlobalEvents.java b/src/main/java/ca/gibstick/discosheep/GlobalEvents.java similarity index 100% rename from src/ca/gibstick/discosheep/GlobalEvents.java rename to src/main/java/ca/gibstick/discosheep/GlobalEvents.java diff --git a/src/ca/gibstick/discosheep/PartyEvents.java b/src/main/java/ca/gibstick/discosheep/PartyEvents.java similarity index 100% rename from src/ca/gibstick/discosheep/PartyEvents.java rename to src/main/java/ca/gibstick/discosheep/PartyEvents.java diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..7df59e8 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,93 @@ +name: DiscoSheep +main: ca.gibstick.discosheep.DiscoSheep +authors: [Gibstick, RangerMauve] +version: 1.1.1 +commands: + ds: + description: "Main DiscoSheep command" + usage: | + [arguments] + Use /ds help for more information + To stop your party, use /ds stop. +permissions: + # If default is set to false, console will not have permission! + discosheep.*: + description: Permission node for all DiscoSheep commands + default: op + children: + discosheep.party: true + discosheep.admin: true + discosheep.party.*: + description: All permissions related to parties + defualt: op + children: + discosheep.party.me: true + discosheep.party.all: true + discosheep.party.fireworks: true + discosheep.party.other: true + discosheep.party.changeperiod: true + discosheep.party.spawnguests: true + discosheep.party.lightning: true + discosheep.admin.*: + description: Suggested permissions for administrators + default: op + children: + discosheep.admin.stopall: true + discosheep.admin.reload: true + discosheep.admin.changedefaults: true + discosheep.admin.saveconfig: true + discosheep.admin.toggleonjoin: true + discosheep.party.me: + description: Allows a player to have a party of one + default: op + discosheep.party.all: + description: Allows a player to call a server-wide party + default: op + discosheep.admin.stopall: + description: Allows a player to stop all parties on the server + default: op + discosheep.party.fireworks: + description: Allows a player to enable have parties with fireworks + default: op + discosheep.admin.reload: + description: Allows a player to reload settings from config.yml + default: op + discosheep.party.other: + description: Allows a player to call parties for other people, including themselves. + default: op + children: + discosheep.party.me: true + discosheep.party.changeperiod: + description: Allows a player to use the -p switch + default: op + discosheep.admin.changedefaults: + description: Allows a player to change the default settings + default: op + discosheep.admin.saveconfig: + description: Allows a player to save the config with current values set in memory + default: op + discosheep.party.onjoin: + description: Gives a player a disco party on join + default: false + discosheep.party.spawnguests: + description: Allow a player to spawn other mobs + default: op + discosheep.admin.toggleonjoin: + description: Allow a player to toggle party-on-join functionality (force disable) + default: op + discosheep.party.lightning: + description: Allow a player to use lightning for parties + default: op + # FOR BACKWARDS COMPAT FROM 1.1 TO 1.1.1 + discosheep.party: + children: + discosheep.party.me: true + discosheep.partyall: + children: + discosheep.party.all: true + discosheep.reload: + children: + discoshep.admin.reload: true + discosheep.stopall: + children: + discosheep.admin.stopall: true \ No newline at end of file