From d30bd96a2a74d35aeb5f548bcdea28560bf74919 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sat, 22 Aug 2020 17:24:46 +0200 Subject: [PATCH] Add support for picking `nothing`. This commit introduces the strange concept of a singleton ThingPicker that only ever picks `null`. The purpose of this picker is to allow for a type of "loot table" experience similar to that found in other games. An example would be a piece of equipment that only has a 50 % chance of dropping. With the current state of MobArena, it would be necessary to something conjure up a CommandThing or something to emulate nothingness, but now there is native support for it with the `nothing` keyword. The nullability of rewards also has the side effect that we got to clean up the MASpawnThread `addReward` method a bit. Closes #638 --- changelog.md | 1 + .../garbagemule/MobArena/MASpawnThread.java | 9 ++------ .../com/garbagemule/MobArena/MobArena.java | 2 ++ .../MobArena/things/NothingPicker.java | 21 +++++++++++++++++++ .../MobArena/things/NothingPickerParser.java | 13 ++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/garbagemule/MobArena/things/NothingPicker.java create mode 100644 src/main/java/com/garbagemule/MobArena/things/NothingPickerParser.java diff --git a/changelog.md b/changelog.md index 8b70646..d3d9c2d 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,7 @@ These changes will (most likely) be included in the next version. - New per-arena setting `arena-warp-offset` can be used to spread out players randomly by an offset from the arena warp. This should help prevent players taking suffocation damage. - New per-arena setting `announcer-type` determines where to display per-arena announcements such as wave spawns, auto start timers, boss abilities, and death messages. Options are `title` (default) or `chat`. - It is now possible to group rewards. For example, `all(stick, bone)` results a stick and a bone, while `random(all(stick, bone), all(dirt, stone))` results in getting _either_ a stick and a bone _or_ a dirt block and a stone block. +- The new `nothing` keyword can be used to _not_ grant a reward. This can be used in a crude way to create "loot table"-style reward systems where there is a _chance_ that something is reward, but it might also just be nothing. - The Root Target ability now uses potion effects (slowness, slow falling, and negative jump boost) instead of repeated teleports. This should make for a smoother root experience. - Using `spectate-on-death: true` no longer forces players out to their join location/exit warp before moving them to the spectator area. This should prevent "jumpy" behavior in multi-world setups. - Players should now properly respawn at the spectator area rather than at world spawn on servers with plugins that override respawn locations. diff --git a/src/main/java/com/garbagemule/MobArena/MASpawnThread.java b/src/main/java/com/garbagemule/MobArena/MASpawnThread.java index 7b5d07a..1d1ff54 100644 --- a/src/main/java/com/garbagemule/MobArena/MASpawnThread.java +++ b/src/main/java/com/garbagemule/MobArena/MASpawnThread.java @@ -392,13 +392,8 @@ public class MASpawnThread implements Runnable private void addReward(ThingPicker picker) { for (Player p : arena.getPlayersInArena()) { Thing reward = picker.pick(); - rewardManager.addReward(p, reward); - - if (reward == null) { - arena.getMessenger().tell(p, "ERROR! Problem with rewards. Notify server host!"); - plugin.getLogger().warning("Could not add null reward. Please check the config-file!"); - } - else { + if (reward != null) { + rewardManager.addReward(p, reward); arena.getMessenger().tell(p, Msg.WAVE_REWARD, reward.toString()); } } diff --git a/src/main/java/com/garbagemule/MobArena/MobArena.java b/src/main/java/com/garbagemule/MobArena/MobArena.java index da96e74..ebb1ff6 100644 --- a/src/main/java/com/garbagemule/MobArena/MobArena.java +++ b/src/main/java/com/garbagemule/MobArena/MobArena.java @@ -16,6 +16,7 @@ import com.garbagemule.MobArena.metrics.VaultChart; import com.garbagemule.MobArena.signs.ArenaSign; import com.garbagemule.MobArena.signs.SignBootstrap; import com.garbagemule.MobArena.signs.SignListeners; +import com.garbagemule.MobArena.things.NothingPickerParser; import com.garbagemule.MobArena.things.RandomThingPickerParser; import com.garbagemule.MobArena.things.ThingGroupPickerParser; import com.garbagemule.MobArena.things.ThingManager; @@ -71,6 +72,7 @@ public class MobArena extends JavaPlugin pickman = new ThingPickerManager(thingman); pickman.register(new ThingGroupPickerParser(pickman)); pickman.register(new RandomThingPickerParser(pickman, random)); + pickman.register(new NothingPickerParser()); } public void onEnable() { diff --git a/src/main/java/com/garbagemule/MobArena/things/NothingPicker.java b/src/main/java/com/garbagemule/MobArena/things/NothingPicker.java new file mode 100644 index 0000000..053819e --- /dev/null +++ b/src/main/java/com/garbagemule/MobArena/things/NothingPicker.java @@ -0,0 +1,21 @@ +package com.garbagemule.MobArena.things; + +class NothingPicker implements ThingPicker { + + private static final NothingPicker instance = new NothingPicker(); + + @Override + public Thing pick() { + return null; + } + + @Override + public String toString() { + return "nothing"; + } + + public static NothingPicker getInstance() { + return instance; + } + +} diff --git a/src/main/java/com/garbagemule/MobArena/things/NothingPickerParser.java b/src/main/java/com/garbagemule/MobArena/things/NothingPickerParser.java new file mode 100644 index 0000000..25d2d44 --- /dev/null +++ b/src/main/java/com/garbagemule/MobArena/things/NothingPickerParser.java @@ -0,0 +1,13 @@ +package com.garbagemule.MobArena.things; + +public class NothingPickerParser implements ThingPickerParser { + + @Override + public ThingPicker parse(String s) { + if (!s.equalsIgnoreCase("nothing")) { + return null; + } + return NothingPicker.getInstance(); + } + +}