Skip to content

Commit

Permalink
Fix particles for Spigot 1.13+
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed Apr 12, 2019
1 parent a8ae864 commit 7f731f5
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 194 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
group 'com.cjburkey'
version '0.0.6'

project.ext.spigotVersion = '1.12.2-R0.1-SNAPSHOT'
project.ext.spigotVersion = '1.13.2-R0.1-SNAPSHOT'
project.ext.vaultApiVersion = '1.7'

project.ext.spigotFile = new File('./run/spigot.jar')
Expand Down
77 changes: 0 additions & 77 deletions pom.xml

This file was deleted.

43 changes: 21 additions & 22 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cjburkey.claimchunk.chunk.ChunkHandler;
import com.cjburkey.claimchunk.chunk.ChunkPos;
import com.cjburkey.claimchunk.cmd.AutoTabCompletion;
import com.cjburkey.claimchunk.cmd.CommandHandler;
import com.cjburkey.claimchunk.cmd.Commands;
import com.cjburkey.claimchunk.data.DataConversion;
Expand All @@ -10,8 +11,8 @@
import com.cjburkey.claimchunk.event.PlayerMovementHandler;
import com.cjburkey.claimchunk.player.DataPlayer;
import com.cjburkey.claimchunk.player.PlayerHandler;
import com.cjburkey.claimchunk.tab.AutoTabCompletion;
import java.io.File;
import java.util.Objects;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -20,10 +21,6 @@ public final class ClaimChunk extends JavaPlugin {
private static ClaimChunk instance;

private boolean useEcon = false;
private boolean useSql = false;

private File chunkFile;
private File plyFile;

private CommandHandler cmd;
private Commands cmds;
Expand All @@ -36,14 +33,16 @@ public void onLoad() {
}

public void onEnable() {
chunkFile = new File(getDataFolder(), "/data/claimedChunks.json");
plyFile = new File(getDataFolder(), "/data/playerData.json");
Utils.log("Spigot version: %s", getServer().getBukkitVersion());

File chunkFile = new File(getDataFolder(), "/data/claimedChunks.json");
File plyFile = new File(getDataFolder(), "/data/playerData.json");

cmd = new CommandHandler();
cmds = new Commands();
economy = new Econ();
playerHandler = new PlayerHandler(useSql, plyFile);
chunkHandler = new ChunkHandler(useSql, chunkFile);
playerHandler = new PlayerHandler(false, plyFile);
chunkHandler = new ChunkHandler(false, chunkFile);

File oldChunks = new File(getDataFolder(), "/data/claimed.chks");
File oldCache = new File(getDataFolder(), "/data/playerCache.dat");
Expand All @@ -62,14 +61,13 @@ public void onEnable() {

if (useEcon) {
if (!economy.setupEconomy(this)) {
Utils.err(
"Economy could not be setup. Make sure that you have an economy plugin (like Essentials) installed. ClaimChunk has been disabled.");
Utils.err("Economy could not be setup. Make sure that you have an economy plugin (like Essentials) installed. ClaimChunk has been disabled.");
disable();
return;
}
Utils.log("Economy set up.");
getServer().getScheduler().scheduleSyncDelayedTask(this,
() -> Utils.log("Money Format: " + economy.format(99132.76)), 0L); // Once everything is loaded.
() -> Utils.log("Money Format: %s", economy.format(99132.76d)), 0L); // Once everything is loaded.
} else {
Utils.log("Economy not enabled. Either it was disabled with config or Vault was not found.");
}
Expand Down Expand Up @@ -106,14 +104,13 @@ public void onEnable() {

private void handleAutoUnclaim() {
int length = Config.getInt("chunks", "automaticUnclaimSeconds");
// Less than a second is insane and stupid (so we have to check)
if (length < 1) {
return;
}
// Less than will disable the check
if (length < 1) return;

long time = System.currentTimeMillis();
for (Player player : getServer().getOnlinePlayers()) {
playerHandler.getPlayer(player.getUniqueId()).lastOnlineTime = time;
Utils.log("Time: " + time);
Utils.log("Time: %s", time);
}
for (DataPlayer player : playerHandler.getJoinedPlayers()) {
if (!player.unclaimedAllChunks && player.lastOnlineTime < (time - (1000 * length))) {
Expand All @@ -125,7 +122,7 @@ private void handleAutoUnclaim() {
e.printStackTrace();
}
}
Utils.log("Unclaimed all chunks of player \"" + player.lastIgn + "\" (" + player.player + ")");
Utils.log("Unclaimed all chunks of player \"%s\" (%s)", player.lastIgn, player.player);
player.unclaimedAllChunks = true;
}
}
Expand Down Expand Up @@ -155,13 +152,14 @@ private void setupEvents() {

private void setupCommands() {
cmds.register(cmd);
getCommand("chunk").setExecutor(cmd);
getCommand("chunk").setTabCompleter(new AutoTabCompletion());
Objects.requireNonNull(getCommand("chunk")).setExecutor(cmd);
Objects.requireNonNull(getCommand("chunk")).setTabCompleter(new AutoTabCompletion());
}

private void scheduleDataSaver() {
// From minutes, calculate after how long in ticks to save data.
int saveTimeTicks = Config.getInt("data", "saveDataInterval") * 60 * 20;

// Async because possible lag when saving and loading.
getServer().getScheduler().runTaskTimerAsynchronously(this, this::reloadData, saveTimeTicks, saveTimeTicks);
}
Expand All @@ -175,7 +173,7 @@ private void reloadData() {
playerHandler.readFromDisk();
} catch (Exception e) {
e.printStackTrace();
Utils.log("Couldn't reload data: \"" + e.getMessage() + "\"");
Utils.log("Couldn't reload data: \"%s\"", e.getMessage());
}
}

Expand Down Expand Up @@ -208,7 +206,8 @@ public static ClaimChunk getInstance() {
}

public static void main(String[] args) {
System.out.println("Please put this in your /plugins/ folder.");
System.out.println("Please put this jar file in your /plugins/ folder.");
System.exit(0);
}

}
16 changes: 8 additions & 8 deletions src/main/java/com/cjburkey/claimchunk/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public final class Utils {

private static final Logger log = Logger.getLogger("Minecraft");

public static void log(Object msg) {
log.info(prepMsg(msg));
public static void log(String msg, Object... data) {
log.info(prepMsg(msg, data));
}

public static void err(Object msg) {
log.severe(prepMsg(msg));
public static void err(String msg, Object... data) {
log.severe(prepMsg(msg, data));
}

private static String color(String in) {
Expand All @@ -25,7 +25,7 @@ private static String color(String in) {
public static String getMsg(String key) {
String out = Config.getString("messages", key);
if (out == null) {
return "messages." + out;
return "messages." + key;
}
return out;
}
Expand Down Expand Up @@ -62,9 +62,9 @@ public static boolean lacksPerm(CommandSender sender, String perm) {
return !sender.hasPermission(perm);
}

private static String prepMsg(Object msg) {
String out = (msg == null) ? "null" : msg.toString();
return String.format("[%s] %s", ClaimChunk.getInstance().getDescription().getPrefix(), color(out));
private static String prepMsg(String msg, Object... data) {
String out = (msg == null) ? "null" : msg;
return String.format("[%s] %s", ClaimChunk.getInstance().getDescription().getPrefix(), color(String.format(out, data)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static boolean inList(Player ply) {
return current.contains(ply.getUniqueId());
}

@SuppressWarnings("unused")
public static void enable(Player ply) {
current.add(ply.getUniqueId());
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/cjburkey/claimchunk/chunk/ChunkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -44,10 +45,10 @@ public ChunkPos claimChunk(World world, int x, int z, UUID player) {
* @param x The chunk x-coord.
* @param z The chunk z-coord.
* @param player The player for whom to claim the chunk.
* @return The chunk position variable
* @return The chunk posautomaticUnclaimSecondsition variable
*/
public ChunkPos claimChunk(String world, int x, int z, UUID player) {
if (isClaimed(ClaimChunk.getInstance().getServer().getWorld(world), x, z)) {
if (isClaimed(Objects.requireNonNull(ClaimChunk.getInstance().getServer().getWorld(world)), x, z)) {
return null;
}
ChunkPos pos = new ChunkPos(world, x, z);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.cjburkey.claimchunk.tab;
package com.cjburkey.claimchunk.cmd;

import com.cjburkey.claimchunk.ClaimChunk;
import com.cjburkey.claimchunk.cmd.Argument;
import com.cjburkey.claimchunk.cmd.ICommand;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
Expand All @@ -24,8 +22,6 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (cmdArg < cmd.getPermittedArguments().length) {
Argument arg = cmd.getPermittedArguments()[cmdArg];
switch (arg.getCompletion()) {
case NONE:
return new ArrayList<>();
case COMMAND:
return getCommands(args[args.length - 1]);
case ONLINE_PLAYER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void registerCommand(Class<? extends ICommand> cls) {
ICommand cmd = cls.newInstance();
if (cmd != null && cmd.getCommand() != null && !cmd.getCommand().trim().isEmpty()
&& !hasCommand(cmd.getCommand())) {
Utils.log(" Registered cmd: " + cmd.getCommand() + " - " + cmd.getDescription());
Utils.log(" Registered cmd: %s - %s", cmd.getCommand(), cmd.getDescription());
cmds.add(cmd);
}
} catch (Exception e) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/cjburkey/claimchunk/cmd/MainHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.cjburkey.claimchunk.chunk.ChunkHandler;
import com.cjburkey.claimchunk.chunk.ChunkPos;
import java.util.UUID;
import java.util.regex.Pattern;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;

Expand All @@ -28,7 +27,7 @@ public static void claimChunk(Player p, Chunk loc) {
Econ e = ClaimChunk.getInstance().getEconomy();
double cost = Config.getDouble("economy", "claimPrice");
if (cost > 0) {
Utils.log(e.getMoney(p.getUniqueId()) + " - " + cost);
Utils.log("%s - %s", e.getMoney(p.getUniqueId()), cost);
if (!e.buy(p.getUniqueId(), cost)) {
Utils.toPlayer(p, Config.getColor("errorColor"), Utils.getMsg("claimNotEnoughMoney"));
return;
Expand Down Expand Up @@ -74,7 +73,7 @@ public static void unclaimChunk(Player p) {
if (reward > 0) {
e.addMoney(p.getUniqueId(), reward);
Utils.toPlayer(p, Config.getColor("errorColor"),
Utils.getMsg("unclaimRefund").replace(Pattern.quote("%%AMT%%"), e.format(reward)));
Utils.getMsg("unclaimRefund").replace("%%AMT%%", e.format(reward)));
refund = true;
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/cjburkey/claimchunk/cmds/CmdHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ public boolean onCall(Player executor, String[] args) {
if (args.length == 0) {
Utils.msg(executor, Config.getColor("infoColor") + "&l---[ ClaimChunk Help ] ---");
for (ICommand cmd : ClaimChunk.getInstance().getCommandHandler().getCmds()) {
String out = (Config.getColor("infoColor") + "/chunk ") +
cmd.getCommand() +
ClaimChunk.getInstance().getCommandHandler().getUsageArgs(cmd);
String out = (Config.getColor("infoColor") + "/chunk ")
+ cmd.getCommand()
+ ' '
+ ClaimChunk.getInstance().getCommandHandler().getUsageArgs(cmd);
Utils.msg(executor, out);
Utils.msg(executor, " " + ChatColor.RED + cmd.getDescription());
}
} else {
ICommand cmd = ClaimChunk.getInstance().getCommandHandler().getCommand(args[0]);
if (cmd != null) {
Utils.msg(executor, Config.getColor("infoColor") + "&l---[ /chunk " + args[0] + " Help ] ---");
String out = (Config.getColor("infoColor") + "/chunk ") +
cmd.getCommand() +
ClaimChunk.getInstance().getCommandHandler().getUsageArgs(cmd);
String out = (Config.getColor("infoColor") + "/chunk ")
+ cmd.getCommand()
+ ' '
+ ClaimChunk.getInstance().getCommandHandler().getUsageArgs(cmd);
Utils.msg(executor, out);
Utils.msg(executor, " " + ChatColor.RED + cmd.getDescription());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static void readChunks(File file, ChunkHandler handler) throws IOExcepti
loadChunkLines(lines.toArray(new String[0]), handler);
}
} else {
Utils.err("File not found: " + file);
Utils.err("File not found: %s", file);
}
}

Expand Down
Loading

0 comments on commit 7f731f5

Please sign in to comment.