Skip to content

Commit

Permalink
- You can have any positive odd radius of chunkbuster now
Browse files Browse the repository at this point in the history
- Water doesn't flow into cleared chunks (for real now)
- Added worldguard hook if you're not using factions
- New config entry for the worldguard hook
- Fixed console nullpointer error with inventories
- Version values updated to 1.0.2
  • Loading branch information
biscuut committed Aug 20, 2018
1 parent 23bd3c0 commit 5ee819d
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 86 deletions.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.biscut.chunkbuster</groupId>
<artifactId>ChunkBuster</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<name>ChunkBuster</name>

<build>
Expand Down Expand Up @@ -41,6 +41,10 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -68,5 +72,10 @@
<version>2.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</project>
29 changes: 24 additions & 5 deletions src/main/java/xyz/biscut/chunkbuster/ChunkBuster.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import xyz.biscut.chunkbuster.events.OtherEvents;
import xyz.biscut.chunkbuster.events.PlayerEvents;
import xyz.biscut.chunkbuster.utils.HookUtils;
import xyz.biscut.chunkbuster.hooks.MCoreFactionsHook;
import xyz.biscut.chunkbuster.hooks.FactionsUUIDHook;
import xyz.biscut.chunkbuster.timers.RemovalQueue;
import xyz.biscut.chunkbuster.utils.ConfigValues;
import xyz.biscut.chunkbuster.utils.Utils;
Expand All @@ -31,19 +29,40 @@ public class ChunkBuster extends JavaPlugin {

@Override
public void onEnable() {
if (getServer().getPluginManager().getPlugin("MassiveCore") != null) {
hookUtils = new HookUtils(0, new MCoreFactionsHook());
int hookType;
if (getServer().getPluginManager().getPlugin("MassiveCore") != null &&
getServer().getPluginManager().getPlugin("Factions") != null) {
getLogger().info("Hooked into MassiveCore Factions");
hookType = 1;
} else if (getServer().getPluginManager().getPlugin("Factions") != null) {
getLogger().info("Hooked into FactionsUUID/SavageFactions");
hookType = 2;
} else {
hookUtils = new HookUtils(1, new FactionsUUIDHook());
getLogger().info("No factions plugin found, attempting to hook into WorldGuard");
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
hookType = 3;
getLogger().info("Hooked into WorldGuard");
} else {
getLogger().severe("No factions or worldguard found, disabling...");
getPluginLoader().disablePlugin(this);
return;
}
}
hookUtils = new HookUtils(hookType);
getConfig().options().copyDefaults(true);
saveDefaultConfig();
utils.updateConfig(this);
Bukkit.getPluginManager().registerEvents(new PlayerEvents(this), this);
Bukkit.getPluginManager().registerEvents(new OtherEvents(this), this);
getCommand("chunkbuster").setExecutor(new ChunkBusterCommand(this));
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RemovalQueue(this), 1L, 1L);
}

@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 @@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(ChatColor.RED + "This isn't a valid number!");
return false;
}
if (chunkArea == 1 || chunkArea == 3 || chunkArea == 5) {
if (chunkArea > 0 && chunkArea % 2 != 0) { // Is positive and odd number
int giveAmount = 1;
if (args.length > 3) {
try {
Expand All @@ -48,7 +48,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
if (giveAmount < 65) {
if (p.getInventory().firstEmpty() != -1) {
ItemStack item = new ItemStack(Material.ENDER_PORTAL_FRAME, giveAmount);
ItemStack item = new ItemStack(main.getConfigValues().getChunkBusterMaterial(), giveAmount, main.getConfigValues().getChunkBusterDamage());
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(main.getConfigValues().getChunkBusterName());
itemMeta.setLore(main.getConfigValues().getChunkBusterLore(chunkArea));
Expand All @@ -65,10 +65,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(ChatColor.RED + "You can only give 64 at a time!");
}
} else {
sender.sendMessage(ChatColor.RED + "The area must be 1, 3, or 5.");
sender.sendMessage(ChatColor.RED + "The area must be greater than 0 and be an odd number!");
}
} else {
sender.sendMessage(ChatColor.RED + "Please specify a chunk area!");
sender.sendMessage(ChatColor.RED + "Please specify the chunk area!");
}
} else {
sender.sendMessage(ChatColor.RED + "This player is not online!");
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/xyz/biscut/chunkbuster/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ public void onChunkBusterPlace(BlockPlaceEvent e) {

@EventHandler
public void onConfirmClick(InventoryClickEvent e) {
if (e.getClickedInventory().getName().contains(main.getConfigValues().getGUITitle())) {
if (e.getClickedInventory() != null && e.getClickedInventory().getName() != null &&
e.getClickedInventory().getName().contains(main.getConfigValues().getGUITitle())) {
e.setCancelled(true);
Player p = (Player)e.getWhoClicked();
Location chunkBusterLocation = main.getChunkBusterLocations().get(e.getWhoClicked());
if (chunkBusterLocation != null) {
int chunkBusterDiameter = e.getWhoClicked().getItemInHand().getItemMeta().getEnchantLevel(Enchantment.LURE);
if (main.getHookUtils().hasFaction(p)) {
if (main.getHookUtils().compareLocPlayerFaction(chunkBusterLocation, p) || main.getHookUtils().isWilderness(chunkBusterLocation)) {
if (main.getHookUtils().compareLocToPlayer(chunkBusterLocation, p) || main.getHookUtils().isWilderness(chunkBusterLocation)) {
if (main.getHookUtils().isWilderness(chunkBusterLocation) && !main.getConfigValues().canPlaceInWilderness()) {
p.sendMessage(main.getConfigValues().getOnlyClaimMessage());
} else {
if (e.getCurrentItem() != null && e.getCurrentItem().getItemMeta().getDisplayName().contains(main.getConfigValues().getConfirmName())) {
if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().getDisplayName().contains(main.getConfigValues().getConfirmName())) {
if (p.getGameMode().equals(GameMode.SURVIVAL) || p.getGameMode().equals(GameMode.ADVENTURE)) {
if (p.getItemInHand().getAmount() <= 1) {
p.getInventory().setItemInHand(null);
Expand All @@ -82,21 +83,21 @@ public void onConfirmClick(InventoryClickEvent e) {
if (main.getConfigValues().getChunkBusterWarmup() > 0) {
int seconds = main.getConfigValues().getChunkBusterWarmup();
new MessageTimer(seconds, p, main).runTaskTimer(main, 0L, 20L);
Bukkit.getScheduler().runTaskLater(main, () -> {
main.getWaterChunks().add(chunkBusterLocation.getChunk());
main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p);
}, 20L * seconds);
Bukkit.getScheduler().runTaskLater(main, () -> main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p), 20L * seconds);
} else {
main.getWaterChunks().add(chunkBusterLocation.getChunk());
main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p);
}
}
}
} else {
if (main.getConfigValues().canPlaceInWilderness()) {
p.sendMessage(main.getConfigValues().getOnlyWildernessClaimMessage());
if (main.getHookUtils().getHookType() == 3) {
p.sendMessage(main.getConfigValues().getRegionProtectedMessage());
} else {
p.sendMessage(main.getConfigValues().getOnlyClaimMessage());
if (main.getConfigValues().canPlaceInWilderness()) {
p.sendMessage(main.getConfigValues().getOnlyWildernessClaimMessage());
} else {
p.sendMessage(main.getConfigValues().getOnlyClaimMessage());
}
}
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/xyz/biscut/chunkbuster/hooks/WorldGuardHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xyz.biscut.chunkbuster.hooks;

import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;

public class WorldGuardHook {

public boolean checkLocationBreakFlag(Location loc, Player p) {
WorldGuardPlugin worldGuardPlugin = (WorldGuardPlugin)Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
RegionContainer container = worldGuardPlugin.getRegionContainer();
RegionQuery query = container.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(loc);
LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(p);
return set.queryState(localPlayer, DefaultFlag.BLOCK_BREAK) == StateFlag.State.ALLOW;
}
}
54 changes: 43 additions & 11 deletions src/main/java/xyz/biscut/chunkbuster/utils/ConfigValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,44 @@ public ConfigValues(ChunkBuster main) {
}

public Material getChunkBusterMaterial() {
String rawMaterial = main.getConfig().getString("chunkbuster.material");
Material mat;
try {
mat = Material.valueOf(main.getConfig().getString("chunkbuster.material"));
} catch (IllegalArgumentException ex) {
mat = Material.ENDER_PORTAL_FRAME;
Bukkit.getLogger().severe("[ChunkBuster] Your chunk buster material is invalid!");
if (rawMaterial.contains(":")) {
String[] materialSplit = rawMaterial.split(":");
try {
mat = Material.valueOf(materialSplit[0]);
} catch (IllegalArgumentException ex) {
mat = Material.ENDER_PORTAL_FRAME;
Bukkit.getLogger().severe("Your chunk buster material is invalid!");
}
} else {
try {
mat = Material.valueOf(rawMaterial);
} catch (IllegalArgumentException ex) {
mat = Material.ENDER_PORTAL_FRAME;
Bukkit.getLogger().severe("Your chunk buster material is invalid!");
}
}
return mat;
}

public short getChunkBusterDamage() {
String rawDamage = main.getConfig().getString("chunkbuster.material");
if (rawDamage.contains(":")) {
String[] materialSplit = rawDamage.split(":");
short damage;
try {
damage = Short.valueOf(materialSplit[1]);
} catch (IllegalArgumentException ex) {
damage = 0;
Bukkit.getLogger().severe("Your chunk buster damage is invalid!");
}
return damage;
} else {
return 0;
}
}

public String getChunkBusterName() { return ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("chunkbuster.name")); }

public List<String> getChunkBusterLore(int chunkRadius) {
Expand Down Expand Up @@ -61,22 +89,22 @@ public ItemStack getConfirmBlockItemStack() {
mat = Material.valueOf(materialSplit[0]);
} catch (IllegalArgumentException ex) {
mat = Material.WOOL;
Bukkit.getLogger().severe("[ChunkBuster] Your accept-block material is invalid!");
Bukkit.getLogger().severe("Your accept-block material is invalid!");
}
short damage;
try {
damage = Short.valueOf(materialSplit[1]);
} catch (IllegalArgumentException ex) {
damage = 0;
Bukkit.getLogger().severe("[ChunkBuster] Your accept-block damage is invalid!");
Bukkit.getLogger().severe("Your accept-block damage is invalid!");
}
return new ItemStack(mat, 1, damage);
} else {
try {
mat = Material.valueOf(rawMaterial);
} catch (IllegalArgumentException ex) {
mat = Material.WOOL;
Bukkit.getLogger().severe("[ChunkBuster] Your accept-block material is invalid!");
Bukkit.getLogger().severe("Your accept-block material is invalid!");
}
return new ItemStack(mat, 1);
}
Expand All @@ -91,22 +119,22 @@ public ItemStack getCancelBlockItemStack() {
mat = Material.valueOf(materialSplit[0]);
} catch (IllegalArgumentException ex) {
mat = Material.WOOL;
Bukkit.getLogger().severe("[ChunkBuster] Your cancel-block material is invalid!");
Bukkit.getLogger().severe("Your cancel-block material is invalid!");
}
short damage;
try {
damage = Short.valueOf(materialSplit[1]);
} catch (IllegalArgumentException ex) {
damage = 0;
Bukkit.getLogger().severe("[ChunkBuster] Your cancel-block damage is invalid!");
Bukkit.getLogger().severe("Your cancel-block damage is invalid!");
}
return new ItemStack(mat, 1, damage);
} else {
try {
mat = Material.valueOf(rawMaterial);
} catch (IllegalArgumentException ex) {
mat = Material.WOOL;
Bukkit.getLogger().severe("[ChunkBuster] Your cancel-block material is invalid!");
Bukkit.getLogger().severe("Your cancel-block material is invalid!");
}
return new ItemStack(mat, 1);
}
Expand Down Expand Up @@ -158,4 +186,8 @@ public String getClearingSecondsMessage(int seconds) {
return ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("messages.clearing-in-seconds")
.replace("{seconds}", String.valueOf(seconds)));
}

public String getRegionProtectedMessage() {
return ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("messages.region-protected"));
}
}
Loading

0 comments on commit 5ee819d

Please sign in to comment.