Skip to content

Commit

Permalink
Added no fall damage config option (apparently didn't add it already)…
Browse files Browse the repository at this point in the history
…. Other small improvements.
  • Loading branch information
biscuut committed Feb 27, 2019
1 parent cb5593b commit 308eabc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ChunkBusterPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<artifactId>ChunkBusterPlugin</artifactId>
<packaging>jar</packaging>
<name>ChunkBusterPlugin</name>
<version>1.2.4</version>
<version>1.2.5</version>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class ChunkBuster extends JavaPlugin {
@Override
public void onEnable() {
hookUtils = new HookUtils(this);
getConfig().options().copyDefaults(true);
saveDefaultConfig();
utils.updateConfig(this);
Bukkit.getPluginManager().registerEvents(new PlayerEvents(this), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
import codes.biscuit.chunkbuster.timers.MessageTimer;
import codes.biscuit.chunkbuster.timers.SoundTimer;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerJoinEvent;
Expand All @@ -27,8 +25,9 @@
public class PlayerEvents implements Listener {

private ChunkBuster main;
private Map<Player, Location> chunkBusterLocations = new HashMap<>();
private Map<Player, Long> playerCooldowns = new HashMap<>();
private Map<OfflinePlayer, Location> chunkBusterLocations = new HashMap<>();
private Map<OfflinePlayer, Long> playerCooldowns = new HashMap<>();
private Map<OfflinePlayer, Long> noFallDamage = new HashMap<>();

public PlayerEvents(ChunkBuster main) {
this.main = main;
Expand Down Expand Up @@ -186,12 +185,18 @@ public void onConfirmClick(InventoryClickEvent e) {
p.playSound(p.getLocation(), main.getConfigValues().getClearingSoundString(), main.getConfigValues().getClearingSoundVolume(), main.getConfigValues().getClearingSoundPitch());
}
main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p);
if (main.getConfigValues().getNoFallMillis() > 0) {
noFallDamage.put(p, System.currentTimeMillis() + main.getConfigValues().getNoFallMillis());
}
}, 20L * seconds);
} else {
if (main.getConfigValues().clearingSoundEnabled()) {
p.playSound(p.getLocation(), main.getConfigValues().getClearingSoundString(), main.getConfigValues().getClearingSoundVolume(), main.getConfigValues().getClearingSoundPitch());
}
main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p);
if (main.getConfigValues().getNoFallMillis() > 0) {
noFallDamage.put(p, System.currentTimeMillis() + main.getConfigValues().getNoFallMillis());
}
}
} else if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().getDisplayName().contains(main.getConfigValues().getCancelName())) {
chunkBusterLocations.remove(p);
Expand Down Expand Up @@ -237,4 +242,18 @@ public void onJoin(PlayerJoinEvent e) {
main.getUtils().checkUpdates(e.getPlayer());
}
}

@EventHandler(ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
if (e.getCause() == EntityDamageEvent.DamageCause.FALL && e.getEntity() instanceof Player) {
Player p = (Player)e.getEntity();
if (noFallDamage.containsKey(p)) {
if (noFallDamage.get(p) >= System.currentTimeMillis()) {
e.setCancelled(true);
} else {
noFallDamage.remove(p);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ boolean compareLocPlayerFaction(Location loc, Player p) {

boolean checkRole(Player p, String role) {
Role playerRole = FPlayers.getInstance().getByPlayer(p).getRole();
if (playerRole == null) {
return false;
}
Role adminRole;
try {
adminRole = Role.valueOf("ADMIN");
Expand All @@ -47,24 +50,28 @@ boolean checkRole(Player p, String role) {
return false;
}
}
Role coLeader = null;
try {
coLeader = Role.valueOf("COLEADER");
} catch (Exception ignored) {}
switch (role) {
case "leader": case "admin":
if (playerRole.equals(adminRole)) {
return true;
}
break;
case "coleader": case "co-leader":
if (playerRole.equals(Role.COLEADER) || playerRole.equals(adminRole)) {
if (playerRole.equals(coLeader) || playerRole.equals(adminRole)) {
return true;
}
break;
case "moderator":
if (playerRole.equals(Role.MODERATOR) || playerRole.equals(Role.COLEADER) || playerRole.equals(adminRole)) {
if (playerRole.equals(Role.MODERATOR) || playerRole.equals(coLeader) || playerRole.equals(adminRole)) {
return true;
}
break;
case "member": case "normal":
if (playerRole.equals(Role.NORMAL) || playerRole.equals(Role.MODERATOR) || playerRole.equals(Role.COLEADER) || playerRole.equals(adminRole)) {
if (playerRole.equals(Role.NORMAL) || playerRole.equals(Role.MODERATOR) || playerRole.equals(coLeader) || playerRole.equals(adminRole)) {
return true;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,8 @@ public boolean worldguardHookEnabled() {
public boolean townyHookEnabled() {
return main.getConfig().getBoolean("hooks.towny");
}

public int getNoFallMillis() {
return main.getConfig().getInt("no-fall-seconds")*1000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class Utils {

private ChunkBuster main;
private HashSet<Chunk> waterChunks = new HashSet<>();
private Set<Chunk> waterChunks = new HashSet<>();

public Utils(ChunkBuster main) {
this.main = main;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
}

public void updateConfig(ChunkBuster main) {
if (main.getConfigValues().getConfigVersion() < 1.9) {
if (main.getConfigValues().getConfigVersion() < 2.0) {
Map<String, Object> oldValues = new HashMap<>();
for (String oldKey : main.getConfig().getKeys(true)) {
oldValues.put(oldKey, main.getConfig().get(oldKey));
Expand All @@ -105,7 +105,7 @@ public void updateConfig(ChunkBuster main) {
main.getConfig().set(newKey, oldValues.get(newKey));
}
}
main.getConfig().set("config-version", 1.9);
main.getConfig().set("config-version", 2.0);
main.saveConfig();
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public void checkUpdates(Player p) {
} catch (Exception ignored) {}
}

public HashSet<Chunk> getWaterChunks() { return waterChunks; }
public Set<Chunk> getWaterChunks() { return waterChunks; }

public ItemStack getChunkBusterItem(int giveAmount, int chunkArea) {
ItemStack item = new ItemStack(main.getConfigValues().getChunkBusterMaterial(), giveAmount, main.getConfigValues().getChunkBusterDamage());
Expand Down
5 changes: 4 additions & 1 deletion ChunkBusterPlugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ can-place-in-wilderness: true
# The time you must wait before using another chunkbuster, in seconds. Set this to 0 for no cooldown.
cooldown: 0

# The amount of time that the player takes no fall damage after a chunk starts clearing. Set to 0 to disable.
no-fall-seconds: 5

# Chunkbusters clear between this minimum value and the maximum value (both inclusive). 0 and 255 means the whole chunk.
# You can use "{player}" for the player"s Y-coordinate.
minimum-y: 0
Expand Down Expand Up @@ -127,4 +130,4 @@ minimum-factions-role: "any"
show-update-messages: true

# Please do not edit :)
config-version: 1.9
config-version: 2.0

0 comments on commit 308eabc

Please sign in to comment.