Skip to content

Commit 308eabc

Browse files
committed
Added no fall damage config option (apparently didn't add it already). Other small improvements.
1 parent cb5593b commit 308eabc

File tree

7 files changed

+48
-16
lines changed

7 files changed

+48
-16
lines changed

ChunkBusterPlugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<artifactId>ChunkBusterPlugin</artifactId>
1010
<packaging>jar</packaging>
1111
<name>ChunkBusterPlugin</name>
12-
<version>1.2.4</version>
12+
<version>1.2.5</version>
1313

1414
<repositories>
1515
<repository>

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/ChunkBuster.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class ChunkBuster extends JavaPlugin {
1818
@Override
1919
public void onEnable() {
2020
hookUtils = new HookUtils(this);
21-
getConfig().options().copyDefaults(true);
2221
saveDefaultConfig();
2322
utils.updateConfig(this);
2423
Bukkit.getPluginManager().registerEvents(new PlayerEvents(this), this);

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/events/PlayerEvents.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
import codes.biscuit.chunkbuster.timers.MessageTimer;
55
import codes.biscuit.chunkbuster.timers.SoundTimer;
66
import net.md_5.bungee.api.ChatColor;
7-
import org.bukkit.Bukkit;
8-
import org.bukkit.GameMode;
9-
import org.bukkit.Location;
10-
import org.bukkit.Material;
7+
import org.bukkit.*;
118
import org.bukkit.enchantments.Enchantment;
129
import org.bukkit.entity.Player;
1310
import org.bukkit.event.EventHandler;
1411
import org.bukkit.event.EventPriority;
1512
import org.bukkit.event.Listener;
1613
import org.bukkit.event.block.BlockPlaceEvent;
14+
import org.bukkit.event.entity.EntityDamageEvent;
1715
import org.bukkit.event.inventory.InventoryClickEvent;
1816
import org.bukkit.event.inventory.InventoryCloseEvent;
1917
import org.bukkit.event.player.PlayerJoinEvent;
@@ -27,8 +25,9 @@
2725
public class PlayerEvents implements Listener {
2826

2927
private ChunkBuster main;
30-
private Map<Player, Location> chunkBusterLocations = new HashMap<>();
31-
private Map<Player, Long> playerCooldowns = new HashMap<>();
28+
private Map<OfflinePlayer, Location> chunkBusterLocations = new HashMap<>();
29+
private Map<OfflinePlayer, Long> playerCooldowns = new HashMap<>();
30+
private Map<OfflinePlayer, Long> noFallDamage = new HashMap<>();
3231

3332
public PlayerEvents(ChunkBuster main) {
3433
this.main = main;
@@ -186,12 +185,18 @@ public void onConfirmClick(InventoryClickEvent e) {
186185
p.playSound(p.getLocation(), main.getConfigValues().getClearingSoundString(), main.getConfigValues().getClearingSoundVolume(), main.getConfigValues().getClearingSoundPitch());
187186
}
188187
main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p);
188+
if (main.getConfigValues().getNoFallMillis() > 0) {
189+
noFallDamage.put(p, System.currentTimeMillis() + main.getConfigValues().getNoFallMillis());
190+
}
189191
}, 20L * seconds);
190192
} else {
191193
if (main.getConfigValues().clearingSoundEnabled()) {
192194
p.playSound(p.getLocation(), main.getConfigValues().getClearingSoundString(), main.getConfigValues().getClearingSoundVolume(), main.getConfigValues().getClearingSoundPitch());
193195
}
194196
main.getUtils().clearChunks(chunkBusterDiameter, chunkBusterLocation, p);
197+
if (main.getConfigValues().getNoFallMillis() > 0) {
198+
noFallDamage.put(p, System.currentTimeMillis() + main.getConfigValues().getNoFallMillis());
199+
}
195200
}
196201
} else if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().getDisplayName().contains(main.getConfigValues().getCancelName())) {
197202
chunkBusterLocations.remove(p);
@@ -237,4 +242,18 @@ public void onJoin(PlayerJoinEvent e) {
237242
main.getUtils().checkUpdates(e.getPlayer());
238243
}
239244
}
245+
246+
@EventHandler(ignoreCancelled = true)
247+
public void onDamage(EntityDamageEvent e) {
248+
if (e.getCause() == EntityDamageEvent.DamageCause.FALL && e.getEntity() instanceof Player) {
249+
Player p = (Player)e.getEntity();
250+
if (noFallDamage.containsKey(p)) {
251+
if (noFallDamage.get(p) >= System.currentTimeMillis()) {
252+
e.setCancelled(true);
253+
} else {
254+
noFallDamage.remove(p);
255+
}
256+
}
257+
}
258+
}
240259
}

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/hooks/FactionsUUIDHook.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ boolean compareLocPlayerFaction(Location loc, Player p) {
3737

3838
boolean checkRole(Player p, String role) {
3939
Role playerRole = FPlayers.getInstance().getByPlayer(p).getRole();
40+
if (playerRole == null) {
41+
return false;
42+
}
4043
Role adminRole;
4144
try {
4245
adminRole = Role.valueOf("ADMIN");
@@ -47,24 +50,28 @@ boolean checkRole(Player p, String role) {
4750
return false;
4851
}
4952
}
53+
Role coLeader = null;
54+
try {
55+
coLeader = Role.valueOf("COLEADER");
56+
} catch (Exception ignored) {}
5057
switch (role) {
5158
case "leader": case "admin":
5259
if (playerRole.equals(adminRole)) {
5360
return true;
5461
}
5562
break;
5663
case "coleader": case "co-leader":
57-
if (playerRole.equals(Role.COLEADER) || playerRole.equals(adminRole)) {
64+
if (playerRole.equals(coLeader) || playerRole.equals(adminRole)) {
5865
return true;
5966
}
6067
break;
6168
case "moderator":
62-
if (playerRole.equals(Role.MODERATOR) || playerRole.equals(Role.COLEADER) || playerRole.equals(adminRole)) {
69+
if (playerRole.equals(Role.MODERATOR) || playerRole.equals(coLeader) || playerRole.equals(adminRole)) {
6370
return true;
6471
}
6572
break;
6673
case "member": case "normal":
67-
if (playerRole.equals(Role.NORMAL) || playerRole.equals(Role.MODERATOR) || playerRole.equals(Role.COLEADER) || playerRole.equals(adminRole)) {
74+
if (playerRole.equals(Role.NORMAL) || playerRole.equals(Role.MODERATOR) || playerRole.equals(coLeader) || playerRole.equals(adminRole)) {
6875
return true;
6976
}
7077
break;

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/utils/ConfigValues.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,8 @@ public boolean worldguardHookEnabled() {
438438
public boolean townyHookEnabled() {
439439
return main.getConfig().getBoolean("hooks.towny");
440440
}
441+
442+
public int getNoFallMillis() {
443+
return main.getConfig().getInt("no-fall-seconds")*1000;
444+
}
441445
}

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/utils/Utils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class Utils {
2626

2727
private ChunkBuster main;
28-
private HashSet<Chunk> waterChunks = new HashSet<>();
28+
private Set<Chunk> waterChunks = new HashSet<>();
2929

3030
public Utils(ChunkBuster main) {
3131
this.main = main;
@@ -93,7 +93,7 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
9393
}
9494

9595
public void updateConfig(ChunkBuster main) {
96-
if (main.getConfigValues().getConfigVersion() < 1.9) {
96+
if (main.getConfigValues().getConfigVersion() < 2.0) {
9797
Map<String, Object> oldValues = new HashMap<>();
9898
for (String oldKey : main.getConfig().getKeys(true)) {
9999
oldValues.put(oldKey, main.getConfig().get(oldKey));
@@ -105,7 +105,7 @@ public void updateConfig(ChunkBuster main) {
105105
main.getConfig().set(newKey, oldValues.get(newKey));
106106
}
107107
}
108-
main.getConfig().set("config-version", 1.9);
108+
main.getConfig().set("config-version", 2.0);
109109
main.saveConfig();
110110
}
111111
}
@@ -149,7 +149,7 @@ public void checkUpdates(Player p) {
149149
} catch (Exception ignored) {}
150150
}
151151

152-
public HashSet<Chunk> getWaterChunks() { return waterChunks; }
152+
public Set<Chunk> getWaterChunks() { return waterChunks; }
153153

154154
public ItemStack getChunkBusterItem(int giveAmount, int chunkArea) {
155155
ItemStack item = new ItemStack(main.getConfigValues().getChunkBusterMaterial(), giveAmount, main.getConfigValues().getChunkBusterDamage());

ChunkBusterPlugin/src/main/resources/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ can-place-in-wilderness: true
3434
# The time you must wait before using another chunkbuster, in seconds. Set this to 0 for no cooldown.
3535
cooldown: 0
3636

37+
# The amount of time that the player takes no fall damage after a chunk starts clearing. Set to 0 to disable.
38+
no-fall-seconds: 5
39+
3740
# Chunkbusters clear between this minimum value and the maximum value (both inclusive). 0 and 255 means the whole chunk.
3841
# You can use "{player}" for the player"s Y-coordinate.
3942
minimum-y: 0
@@ -127,4 +130,4 @@ minimum-factions-role: "any"
127130
show-update-messages: true
128131

129132
# Please do not edit :)
130-
config-version: 1.9
133+
config-version: 2.0

0 commit comments

Comments
 (0)