Skip to content

Commit

Permalink
A bunch of bug fixes that i forgot, and update to 1.14.
Browse files Browse the repository at this point in the history
  • Loading branch information
biscuut committed May 27, 2019
1 parent 25d7cb6 commit 95a6972
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 81 deletions.
12 changes: 12 additions & 0 deletions ChunkBusterPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
</repositories>

<dependencies>
<!--<dependency>-->
<!--<groupId>org.spigotmc</groupId>-->
<!--<artifactId>spigot-api</artifactId>-->
<!--<version>1.14.1-R0.1-SNAPSHOT</version>-->
<!--<scope>provided</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.spigotmc</groupId>-->
<!--<artifactId>spigot</artifactId>-->
<!--<version>1.14.1-R0.1-SNAPSHOT</version>-->
<!--<scope>provided</scope>-->
<!--</dependency>-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public void onEnable() {
getCommand("chunkbuster").setTabCompleter(chunkBusterCommand);
}

@Override
public void onDisable() {
Bukkit.getScheduler().cancelTasks(this);
}

public Utils getUtils() { return utils; }

public ConfigValues getConfigValues() { return configValues; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;

public class ChunkBusterCommand implements TabExecutor {

Expand Down Expand Up @@ -65,7 +62,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
}
ItemStack item = main.getUtils().getChunkBusterItem(giveAmount, chunkArea);
HashMap excessItems;
if (!main.getConfigValues().dropFullInv()) {
if (giveAmount < 65) {
if (p.getInventory().firstEmpty() == -1) {
Expand All @@ -77,17 +73,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}
}
excessItems = p.getInventory().addItem(item);
for (Object excessItem : excessItems.values()) {
int itemCount = ((ItemStack) excessItem).getAmount();
Map<Integer, ItemStack> excessItems = p.getInventory().addItem(item);
for (ItemStack excessItem : excessItems.values()) {
int itemCount = excessItem.getAmount();
while (itemCount > 64) {
((ItemStack) excessItem).setAmount(64);
p.getWorld().dropItemNaturally(p.getLocation(), (ItemStack) excessItem);
excessItem.setAmount(64);
p.getWorld().dropItemNaturally(p.getLocation(), excessItem);
itemCount = itemCount - 64;
}
if (itemCount > 0) {
((ItemStack) excessItem).setAmount(itemCount);
p.getWorld().dropItemNaturally(p.getLocation(), (ItemStack) excessItem);
excessItem.setAmount(itemCount);
p.getWorld().dropItemNaturally(p.getLocation(), excessItem);
}
}
main.getUtils().sendMessage(p, ConfigValues.Message.GIVE, p.getName(), giveAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
import org.bukkit.event.block.BlockFromToEvent;
import codes.biscuit.chunkbuster.ChunkBuster;

import java.util.regex.Pattern;

public class OtherEvents implements Listener {

private ChunkBuster main;
private int version = -1;

public OtherEvents(ChunkBuster main) {
this.main = main;
}

@EventHandler
public void onWaterFlow(BlockFromToEvent e) {
if (Bukkit.getVersion().contains("1.13")) {
if (version == -1) {
version = Integer.valueOf(Bukkit.getBukkitVersion().split(Pattern.quote("-"))[0].split(Pattern.quote("."))[1]);
}
if (version >= 13) { //Material names are different in 1.13+
if (e.getBlock().getType().equals(Material.WATER) || e.getBlock().getType().equals(Material.LAVA)) {
if (!main.getUtils().getWaterChunks().contains(e.getBlock().getChunk()) && main.getUtils().getWaterChunks().contains(e.getToBlock().getChunk())) {
e.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void onChunkBusterPlace(BlockPlaceEvent e) {

@EventHandler
public void onConfirmClick(InventoryClickEvent e) {
if (e.getWhoClicked() instanceof Player && e.getClickedInventory() != null && e.getClickedInventory().getName() != null &&
e.getClickedInventory().getName().equals(main.getConfigValues().getGUITitle())) {
if (e.getWhoClicked() instanceof Player && e.getClickedInventory() != null && e.getView().getTitle() != null &&
e.getView().getTitle().equals(main.getConfigValues().getGUITitle())) {
e.setCancelled(true);
Player p = (Player)e.getWhoClicked();
Location chunkBusterLocation = chunkBusterLocations.get(p);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void onConfirmClick(InventoryClickEvent e) {
}
if (main.getConfigValues().getChunkBusterWarmup() > 0) {
int seconds = main.getConfigValues().getChunkBusterWarmup();
new MessageTimer(seconds, p, main).runTaskTimer(main, 0L, 20L);
new MessageTimer(seconds, p.getUniqueId(), main).runTaskTimer(main, 0L, 20L);
if (main.getConfigValues().warmupSoundEnabled()) {
new SoundTimer(main, p, (int)((double)seconds / main.getConfigValues().getWarmupSoundInterval())).runTaskTimer(main, 0L, 20L * main.getConfigValues().getWarmupSoundInterval());
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public void onConfirmClick(InventoryClickEvent e) {

@EventHandler
public void onGUIClose(InventoryCloseEvent e) {
if (e.getInventory().getName().contains(main.getConfigValues().getGUITitle()) && e.getPlayer() instanceof Player) {
if (e.getView().getTitle().contains(main.getConfigValues().getGUITitle()) && e.getPlayer() instanceof Player) {
chunkBusterLocations.remove(e.getPlayer());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ boolean compareLocPlayerFaction(Location loc, Player p) {
return locFaction.equals(pFaction) || (locFaction.isWilderness() && main.getConfigValues().canPlaceInWilderness());
}

// This is more complicated than it has to be because of different forks. Trust me, just keep it this way.
boolean checkRole(Player p, String role) {
Role playerRole = FPlayers.getInstance().getByPlayer(p).getRole();
if (playerRole == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ public class HookUtils {
private Map<HookType, Object> enabledHooks = new EnumMap<>(HookType.class);
private ChunkBuster main;


/**
* Construct the instance with the correct hook
* This will automatically create all the hooks and add all the enabled hooks
* to the map above.
*/
public HookUtils(ChunkBuster main) {
this.main = main;
PluginManager pm = main.getServer().getPluginManager();
if (pm.getPlugin("MassiveCore") != null &&
pm.getPlugin("Factions") != null &&
pm.getPlugin("Factions") != null && // Many people have Massivecore on their server when they don't need it, so check dependencies.
pm.getPlugin("Factions").getDescription().getDepend().contains("MassiveCore")) {
main.getLogger().info("Hooked into MassiveCore Factions");
enabledHooks.put(HookType.MCOREFACTIONS, new MCoreFactionsHook(main));
Expand Down Expand Up @@ -50,15 +52,7 @@ public HookUtils(ChunkBuster main) {
}

/**
* Check if a player has a faction
* <p>
* This method isn't always applicable since they may not be using
* a factions hook, so in that case it will return true (since
* as false it will stop all the logic). Otherwise
* it will check using the appropriate factions hook.
* <p>
* @param p The player to check
* @return If this player has a faction
* Check if a player has a faction if the factions hook is enabled
*/
public boolean hasFaction(Player p) {
if (main.getConfigValues().factionsHookEnabled() && enabledHooks.containsKey(HookType.MCOREFACTIONS)) {
Expand All @@ -73,14 +67,7 @@ public boolean hasFaction(Player p) {
}

/**
* Check if a location is wilderness
* <p>
* This method isn't always applicable since they may not be using
* a factions hook, so in that case it will return false. Otherwise
* it will check using the appropriate factions hook.
* <p>
* @param loc The location to check
* @return If this chunk is wilderness
* Check if a location is wilderness if the factions hook is enabled
*/
public boolean isWilderness(Location loc) {
if (main.getConfigValues().factionsHookEnabled() && enabledHooks.containsKey(HookType.MCOREFACTIONS)) {
Expand All @@ -95,13 +82,7 @@ public boolean isWilderness(Location loc) {
}

/**
* Compare a location to a player using the appropriate hook
* <p>
* This method will check using all enabled hooks.
* <p>
* @param loc The location to be compared
* @param p The player to be compared
* @return If the player can clear this chunk
* Whether the player can place here, checking all appropriate hooks
*/
public boolean compareLocToPlayer(Location loc, Player p) {
boolean canBuild = true;
Expand All @@ -124,14 +105,7 @@ public boolean compareLocToPlayer(Location loc, Player p) {
}

/**
* Check if a player has the minimum role to place chunkbusters
* <p>
* This method isn't always applicable since they may not be using
* a factions hook, so in that case it will return true. Otherwise
* it will check using the appropriate factions hook.
* <p>
* @param p The player to check
* @return If this player has the minimum role
* Check if a player has the minimum role to place chunkbusters if the factions hook is enabled
*/
public boolean checkRole(Player p) {
if (main.getConfigValues().factionsHookEnabled() && enabledHooks.containsKey(HookType.MCOREFACTIONS)) {
Expand All @@ -147,10 +121,6 @@ public boolean checkRole(Player p) {

/**
* Log a block as removed in CoreProtect
* @param p The player to log
* @param loc The block's location
* @param mat The block's material
* @param damage The block's damage value
*/
public void logBlock(Player p, Location loc, Material mat, byte damage) {
if (main.getConfigValues().coreprotectHookEnabled() && enabledHooks.containsKey(HookType.COREPROTECT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TownyHook {

boolean canBuild(Chunk chunk, Player p) {
if (TownySettings.getTownBlockSize() % 16 == 0) {
if (TownySettings.getTownBlockSize() % 16 == 0) { // If claims are an even 16 block then its much simpler
Block centerBlock = chunk.getBlock(7,chunk.getWorld().getMaxHeight()/2, 7);
return PlayerCacheUtil.getCachePermission(p, centerBlock.getLocation(), centerBlock.getType(), TownyPermission.ActionType.DESTROY);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum MinecraftVersion {
MC1_11_R1(1111),
MC1_12_R1(1121),
MC1_13_R1(1131),
MC1_13_R2(1132);
MC1_13_R2(1132),
MC1_14_R1(1141);

private static MinecraftVersion version;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package codes.biscuit.chunkbuster.timers;

import codes.biscuit.chunkbuster.ChunkBuster;
import codes.biscuit.chunkbuster.utils.ConfigValues;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import codes.biscuit.chunkbuster.ChunkBuster;

import java.util.UUID;

public class MessageTimer extends BukkitRunnable {

private int seconds;
private Player p;
private UUID uuid;
private ChunkBuster main;

public MessageTimer(int seconds, Player p, ChunkBuster main) {
public MessageTimer(int seconds, UUID uuid, ChunkBuster main) {
this.seconds = seconds;
this.p = p;
this.uuid = uuid;
this.main = main;
}

Expand All @@ -23,7 +24,7 @@ public void run() {
cancel();
return;
}
main.getUtils().sendMessage(p, ConfigValues.Message.CLEARING_IN_SECONDS, seconds);
main.getUtils().sendMessage(main.getServer().getPlayer(uuid), ConfigValues.Message.CLEARING_IN_SECONDS, seconds);
if (!main.getConfigValues().sendWarmupEverySecond()) {
cancel();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class ConfigValues {

private ChunkBuster main;


/**
* This class simplifies retrieving config values. If trying to grab a message, please see {@link Utils#sendMessage}
*/
public ConfigValues(ChunkBuster main) {
this.main = main;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class Utils {

private ChunkBuster main;
private Set<Chunk> waterChunks = new HashSet<>();
private Set<Chunk> waterChunks = new HashSet<>(); // The chunks that water should not flow in

public Utils(ChunkBuster main) {
this.main = main;
Expand Down Expand Up @@ -58,7 +58,7 @@ ItemStack itemFromString(String rawItem) {
} catch (IllegalArgumentException ex) {
material = Material.DIRT;
}
short damage = 1;
short damage = 0;
if (rawSplit.length > 1) {
try {
damage = Short.valueOf(rawSplit[1]);
Expand All @@ -84,16 +84,17 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
Set<Material> ignoredBlocks = main.getConfigValues().getIgnoredBlocks();
if (chunkBusterArea % 2 != 0) {
RemovalQueue removalQueue = new RemovalQueue(main, p);
// Variables for the area to loop through
int upperBound = ((chunkBusterArea-1)/2)+1;
int lowerBound = (chunkBusterArea-1)/-2;
for (int y = main.getConfigValues().getMaximumY(p); y >= main.getConfigValues().getMinimumY(p); y--) {
for (int chunkX = lowerBound; chunkX < upperBound; chunkX++) {
for (int chunkZ = lowerBound; chunkZ < upperBound; chunkZ++) {
for (int chunkX = lowerBound; chunkX < upperBound; chunkX++) { // Loop through the area
for (int chunkZ = lowerBound; chunkZ < upperBound; chunkZ++) { // Get the chunk
Chunk chunk = chunkBusterLocation.getWorld().getChunkAt(chunkBusterLocation.getChunk().getX() + chunkX, chunkBusterLocation.getChunk().getZ() + chunkZ);
Location chunkCheckLoc = chunk.getBlock(7, 60, 7).getLocation();
Location chunkCheckLoc = chunk.getBlock(7, 60, 7).getLocation(); // Check the chunk
if (main.getHookUtils().compareLocToPlayer(chunkCheckLoc, p)) {
waterChunks.add(chunk);
for (int x = 0; x < 16; x++) {
for (int x = 0; x < 16; x++) { // Clear the chunk
for (int z = 0; z < 16; z++) {
Block b = chunk.getBlock(x, y, z);
if (!b.getType().equals(Material.AIR) && !ignoredBlocks.contains(b.getType())) {
Expand All @@ -112,7 +113,7 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
}
}

public void updateConfig(ChunkBuster main) {
public void updateConfig(ChunkBuster main) { // Basic config updater that saves the old config, loads the new one, and inserts the old keys
if (main.getConfigValues().getConfigVersion() < 2.1) {
Map<String, Object> oldValues = new HashMap<>();
for (String oldKey : main.getConfig().getKeys(true)) {
Expand All @@ -130,7 +131,7 @@ public void updateConfig(ChunkBuster main) {
}
}

public void checkUpdates(Player p) {
public void checkUpdates(Player p) { // Grabs the version from the spigot api and checks it
try {
URL url = new URL("https://api.spigotmc.org/legacy/update.php?resource=60057");
URLConnection connection = url.openConnection();
Expand Down Expand Up @@ -159,10 +160,10 @@ public void checkUpdates(Player p) {
newVersion.setColor(ChatColor.RED);
newVersion.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/chunkbuster-1-8-1-13-clear-any-area-of-land.60057/"));
p.spigot().sendMessage(newVersion);
break;
return;
} else if (thisVersionNumbers.get(i) > newestVersionNumbers.get(i)) {
p.sendMessage(color("&cYou are running a development version of ChunkBuster, " + main.getDescription().getVersion() + ". The latest online version is " + newestVersion + "."));
break;
return;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ChunkBusterPlugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ chunkbuster:
# 1.12 - https://hub.spigotmc.org/nexus/service/local/repositories/snapshots/archive/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156-javadoc.jar/!/org/bukkit/Material.html
# 1.13 - https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# Damage values supported for < 1.13.
material: "ENDER_PORTAL_FRAME"
material: "ENDER_PORTAL_FRAME" # or END_PORTAL_FRAME in 1.13+
name: "&e\u2734 &a&lChunk Buster &e\u2734"
lore:
- "&7Radius: &e{area}"
Expand Down Expand Up @@ -71,8 +71,8 @@ full-inv-drop-on-floor: false
confirm-gui:
# Maximum 6
rows: 3
confirm-material: "WOOL:5"
cancel-material: "WOOL:14"
confirm-material: "WOOL:5" # or GREEN_WOOL
cancel-material: "WOOL:14" # or RED_WOOL
fill-material: "AIR"
# Please do not leave leave any of these below texts empty ("") please
title: "&7CONFIRM CHUNK BUSTER"
Expand Down

0 comments on commit 95a6972

Please sign in to comment.