mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-27 19:24:43 +02:00
I'm sure I broke something :_:
This commit is contained in:
@ -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<Flag> 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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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<UUID>();
|
||||
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<UUID> helpers, ArrayList<UUID> trusted,
|
||||
ArrayList<UUID> denied, boolean changeTime, long time, boolean rain, String alias,
|
||||
ArrayList<UUID> 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);
|
||||
|
@ -1251,7 +1251,9 @@ public class PlotMain extends JavaPlugin {
|
||||
FlagManager.addFlag(new AbstractFlag(str));
|
||||
}
|
||||
List<String> otherFlags = Arrays.asList(
|
||||
"gamemode"
|
||||
"gamemode",
|
||||
"weather",
|
||||
"time"
|
||||
);
|
||||
for(String str : otherFlags) {
|
||||
FlagManager.addFlag(new AbstractFlag(str));
|
||||
|
@ -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<Flag> 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
|
||||
|
@ -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));
|
||||
|
@ -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) {
|
||||
|
@ -160,7 +160,7 @@ public class DBFunc {
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot
|
||||
* @param plots
|
||||
*/
|
||||
public static void createPlots(ArrayList<Plot> plots) {
|
||||
if (plots.size() == 0) {
|
||||
@ -449,22 +449,7 @@ public class DBFunc {
|
||||
ArrayList<UUID> helpers = plotHelpers(id);
|
||||
ArrayList<UUID> trusted = plotTrusted(id);
|
||||
ArrayList<UUID> 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);
|
||||
|
@ -135,6 +135,16 @@ public class PlayerEvents implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private WeatherType getWeatherType(String str) {
|
||||
str = str.toLowerCase();
|
||||
List<String> 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<String> creative = Arrays.asList("creative" , "cr", "1");
|
||||
@ -151,10 +161,26 @@ public class PlayerEvents implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, GameMode> 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());
|
||||
|
Reference in New Issue
Block a user