diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8eef9a449..5589e6907 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -10,7 +10,15 @@ + + + + + + + + @@ -37,10 +45,10 @@ - - + + - + @@ -56,32 +64,25 @@ + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -89,38 +90,18 @@ - - + + - - - - - - - - - - - - - - - - - - - - - + - - + + @@ -130,32 +111,104 @@ - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -169,28 +222,21 @@ @@ -363,7 +416,37 @@ - @@ -985,7 +1072,7 @@ - + @@ -1040,7 +1127,6 @@ - @@ -1065,7 +1151,8 @@ - @@ -1077,34 +1164,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1112,13 +1171,6 @@ - - - - - - - @@ -1242,14 +1294,6 @@ - - - - - - - - @@ -1423,14 +1467,6 @@ - - - - - - - - @@ -1455,14 +1491,6 @@ - - - - - - - - @@ -1471,12 +1499,23 @@ + + + + + + + + + + + - - + + - + @@ -1491,10 +1530,18 @@ + + + + + + + + - - + + @@ -1503,6 +1550,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java b/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java index d50deabd1..08a656b51 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java @@ -28,6 +28,26 @@ public class FlagManager { return flags.add(flag); } + public static Flag[] removeFlag(Flag[] flags, String r) { + Flag[] f = new Flag[flags.length - 1]; + int index = 0; + for(Flag flag : flags) { + if(!flag.getKey().equals(r)) + f[index++] = flag; + } + return f; + } + + public static Flag[] removeFlag(Set flags, String r) { + Flag[] flagArray = new Flag[flags.size() - 1]; + int index = 0; + for(Flag flag : flags) { + if(!flag.getKey().equals(r)) + flagArray[index++] = flag; + } + return flagArray; + } + /** * Get a list of registered AbstractFlag objects * diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index adf2650ca..ce0e10ed7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -9,21 +9,12 @@ package com.intellectualcrafters.plot; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.WeatherType; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.entity.Player; +import java.util.*; + /** * Functions involving players, plots and locations. * @@ -135,23 +126,7 @@ public class PlayerFunctions { return manager.getPlotId(plotworld, loc); } - /** - * Sets the weather for a player, given the current plot settings - * @param player - * @param plot - */ - public static void togglePlotWeather(Player player, Plot plot) { - player.setPlayerWeather(plot.settings.getRain() ? WeatherType.DOWNFALL : WeatherType.CLEAR); - } - /** - * Sets the time for a player, given the current plot settings - * @param player - * @param plot - */ - public static void togglePlotTime(Player player, Plot plot) { - player.setPlayerTime(plot.settings.getTime(), false); - } /** * Returns the plot a player is currently in. @@ -180,7 +155,7 @@ public class PlayerFunctions { /** * Updates a given plot with another instance * @deprecated - * @param id + * @param plot */ @Deprecated diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index 3e5825735..f6c87a98a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -8,15 +8,14 @@ package com.intellectualcrafters.plot; -import java.util.ArrayList; -import java.util.UUID; - +import com.intellectualcrafters.plot.database.DBFunc; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.entity.Player; -import com.intellectualcrafters.plot.database.DBFunc; +import java.util.ArrayList; +import java.util.UUID; /** * The plot class @@ -85,9 +84,6 @@ public class Plot implements Cloneable { this.helpers = helpers; this.denied = denied; this.trusted = new ArrayList(); - this.settings.setTime(8000l); - this.settings.setRain(false); - this.settings.setTimeChange(false); this.settings.setAlias(""); this.settings.setPosition(PlotHomePosition.DEFAULT); this.delete = false; @@ -108,7 +104,7 @@ public class Plot implements Cloneable { * @param merged */ public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList helpers, ArrayList trusted, - ArrayList denied, boolean changeTime, long time, boolean rain, String alias, + ArrayList denied, String alias, PlotHomePosition position, Flag[] flags, String world, boolean[] merged) { this.id = id; this.settings = new PlotSettings(this); @@ -118,9 +114,6 @@ public class Plot implements Cloneable { this.trusted = trusted; this.helpers = helpers; this.denied = denied; - this.settings.setTime(time); - this.settings.setRain(rain); - this.settings.setTimeChange(changeTime); this.settings.setAlias(alias); this.settings.setPosition(position); this.settings.setMerged(merged); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index c6cce82e8..ca3bf3f29 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -1251,7 +1251,9 @@ public class PlotMain extends JavaPlugin { FlagManager.addFlag(new AbstractFlag(str)); } List otherFlags = Arrays.asList( - "gamemode" + "gamemode", + "weather", + "time" ); for(String str : otherFlags) { FlagManager.addFlag(new AbstractFlag(str)); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java index 191bda6fa..16d594243 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java @@ -8,12 +8,12 @@ package com.intellectualcrafters.plot; +import org.bukkit.block.Biome; + import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import org.bukkit.block.Biome; - /** * plot settings * @@ -32,22 +32,12 @@ public class PlotSettings { * plot biome */ private Biome biome; - /** - * plot rain - */ - private boolean rain; + /** * */ private Set flags; - /** - * plot time - */ - private Long time; - /** - * Change time? - */ - private boolean changeTime; + private PlotHomePosition position; /** @@ -99,19 +89,6 @@ public class PlotSettings { this.biome = b; } - /** - * @param b - */ - public void setTimeChange(boolean b) { - this.changeTime = b; - } - - /** - * @param l - */ - public void setTime(long l) { - this.time = l; - } /** * @return @@ -122,30 +99,7 @@ public class PlotSettings { return this.biome; } - /** - * @return - */ - public boolean getRain() { - return this.rain; - } - public void setRain(boolean b) { - this.rain = b; - } - - /** - * @return - */ - public long getTime() { - return this.time; - } - - /** - * @return - */ - public boolean getChangeTime() { - return this.changeTime; - } /** * @param alias diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index 66295dd02..caf3f5189 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -8,9 +8,8 @@ package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.UUID; - +import com.intellectualcrafters.plot.*; +import com.intellectualcrafters.plot.database.DBFunc; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -18,15 +17,8 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.entity.Player; -import com.intellectualcrafters.plot.C; -import com.intellectualcrafters.plot.PlayerFunctions; -import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHelper; -import com.intellectualcrafters.plot.PlotId; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.PlotWorld; -import com.intellectualcrafters.plot.UUIDHandler; -import com.intellectualcrafters.plot.database.DBFunc; +import java.util.ArrayList; +import java.util.UUID; /** * @author Citymonstret @@ -113,8 +105,6 @@ public class Info extends SubCommand { info = info.replaceAll("%id%", plot.id.toString()); info = info.replaceAll("%biome%", getBiomeAt(plot).toString()); info = info.replaceAll("%owner%", owner); - info = info.replaceAll("%time%", plot.settings.getChangeTime() ? plot.settings.getTime() + "" : "default"); - info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain" : "default"); info = info.replaceAll("%helpers%", getPlayerList(plot.helpers)); info = info.replaceAll("%trusted%", getPlayerList(plot.trusted)); info = info.replaceAll("%denied%", getPlayerList(plot.denied)); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 1bc032a3a..a317eb696 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -8,32 +8,20 @@ package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import com.intellectualcrafters.plot.*; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlotFlagAddEvent; +import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.WeatherType; import org.bukkit.block.Biome; import org.bukkit.entity.Player; -import com.intellectualcrafters.plot.AbstractFlag; -import com.intellectualcrafters.plot.C; -import com.intellectualcrafters.plot.Flag; -import com.intellectualcrafters.plot.FlagManager; -import com.intellectualcrafters.plot.PlayerFunctions; -import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotBlock; -import com.intellectualcrafters.plot.PlotHelper; -import com.intellectualcrafters.plot.PlotHomePosition; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.PlotWorld; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.events.PlotFlagAddEvent; -import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * @author Citymonstret @@ -44,9 +32,9 @@ public class Set extends SubCommand { super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true); } - public static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "rain", + public static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "flag" }; - public static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "r", "fl" }; + public static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" }; @SuppressWarnings("deprecation") @Override @@ -168,31 +156,7 @@ public class Set extends SubCommand { return false; } } - if (args[0].equalsIgnoreCase("rain")) { - if (args.length < 2) { - PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF); - return false; - } - String word = args[1]; - if (!word.equalsIgnoreCase("on") && !word.equalsIgnoreCase("off")) { - PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF); - return true; - } - boolean b = word.equalsIgnoreCase("on"); - DBFunc.setWeather(plr.getWorld().getName(), plot, b); - PlayerFunctions.sendMessage(plr, C.SETTING_UPDATED); - for (Player p : Bukkit.getOnlinePlayers()) { - if (PlayerFunctions.getCurrentPlot(plr).id == plot.id) { - if (b) { - p.setPlayerWeather(WeatherType.DOWNFALL); - } - else { - p.resetPlayerWeather(); - } - } - } - return true; - } + if (args[0].equalsIgnoreCase("home")) { if (args.length < 2) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 6a5d54360..1f7cda3f8 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -160,7 +160,7 @@ public class DBFunc { /** * Create a plot * - * @param plot + * @param plots */ public static void createPlots(ArrayList plots) { if (plots.size() == 0) { @@ -449,22 +449,7 @@ public class DBFunc { ArrayList helpers = plotHelpers(id); ArrayList trusted = plotTrusted(id); ArrayList denied = plotDenied(id); - // boolean changeTime = ((Short) settings.get("custom_time") == - // 0) ? false : true; - long time = 8000l; - // if(changeTime) { - // time = Long.parseLong(settings.get("time").toString()); - // } - // boolean rain = - // Integer.parseInt(settings.get("rain").toString()) == 1 ? true - // : false; - boolean rain; - try { - rain = (int) settings.get("rain") == 1 ? true : false; - } - catch (Exception e) { - rain = false; - } + String alias = (String) settings.get("alias"); if ((alias == null) || alias.equalsIgnoreCase("NEW")) { alias = ""; @@ -489,7 +474,7 @@ public class DBFunc { merged[3 - i] = (merged_int & (1 << i)) != 0; } p = - new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, /* changeTime */false, time, rain, alias, position, flags, worldname, merged); + new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags, worldname, merged); if (plots.containsKey(worldname)) { plots.get(worldname).put((plot_id), p); } @@ -514,31 +499,6 @@ public class DBFunc { return plots; } - /** - * @param plot - * @param rain - */ - public static void setWeather(final String world, final Plot plot, final boolean rain) { - plot.settings.setRain(rain); - runTask(new Runnable() { - @Override - public void run() { - try { - int weather = rain ? 1 : 0; - PreparedStatement stmt = - connection.prepareStatement("UPDATE `plot_settings` SET `rain` = ? WHERE `plot_plot_id` = ?"); - stmt.setInt(1, weather); - stmt.setInt(2, getId(world, plot.id)); - stmt.execute(); - stmt.close(); - } - catch (SQLException e) { - e.printStackTrace(); - Logger.add(LogLevel.WARNING, "Could not set weather for plot " + plot.id); - } - } - }); - } public static void setMerged(final String world, final Plot plot, final boolean[] merged) { plot.settings.setMerged(merged); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java index bd5090d50..74e05f060 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -135,6 +135,16 @@ public class PlayerEvents implements Listener { } } + private WeatherType getWeatherType(String str) { + str = str.toLowerCase(); + List storm = Arrays.asList("storm", "rain", "on"); + if(storm.contains(str)) { + return WeatherType.DOWNFALL; + } else { + return WeatherType.CLEAR; + } + } + private GameMode getGameMode(String str) { str = str.toLowerCase(); List creative = Arrays.asList("creative" , "cr", "1"); @@ -151,10 +161,26 @@ public class PlayerEvents implements Listener { } } + private HashMap previousGamemode = new HashMap<>(); + public void plotEntry(Player player, Plot plot) { if (plot.hasOwner()) { if(plot.settings.getFlag("gamemode") != null) { + if(previousGamemode.containsKey(player.getName())) { + previousGamemode.remove(player.getName()); + } + previousGamemode.put(player.getName(), player.getGameMode()); player.setGameMode(getGameMode(plot.settings.getFlag("gamemode").getValue())); + } + if(plot.settings.getFlag("time") != null) { + try { + int time = Integer.parseInt(plot.settings.getFlag("time").getValue()); + } catch(Exception e) { + plot.settings.setFlags(FlagManager.removeFlag(plot.settings.getFlags(), "time")); + } + } + if(plot.settings.getFlag("weather") != null) { + player.setPlayerWeather(getWeatherType(plot.settings.getFlag("weather").getValue())); } if (C.TITLE_ENTERED_PLOT.s().length() > 2) { String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceFirst("%s", plot.getDisplayName()); @@ -172,12 +198,6 @@ public class PlayerEvents implements Listener { Bukkit.getPluginManager().callEvent(callEvent); } PlayerFunctions.sendMessage(player, plot.settings.getJoinMessage()); - if (plot.settings.getRain()) { - PlayerFunctions.togglePlotWeather(player, plot); - } - if (plot.settings.getChangeTime()) { - PlayerFunctions.togglePlotTime(player, plot); - } } } @@ -186,6 +206,10 @@ public class PlayerEvents implements Listener { PlayerLeavePlotEvent callEvent = new PlayerLeavePlotEvent(player, plot); Bukkit.getPluginManager().callEvent(callEvent); } + if(previousGamemode.containsKey(player.getName())) { + player.setGameMode(previousGamemode.get(player.getName())); + previousGamemode.remove(player.getName()); + } player.resetPlayerTime(); player.resetPlayerWeather(); PlayerFunctions.sendMessage(player, plot.settings.getLeaveMessage());