mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Fixes protection for scooping tropical fish.
https://github.com/BentoBoxWorld/bentobox/issues/349 Also added pagination to protection flags and localized alphabetical sorting of the flags. Also added defensive code should a flag enum be removed but it is still in the island database. In this case it will just be ignored and at the next database object save it will disappear.
This commit is contained in:
parent
98264f03d0
commit
ff2983629d
@ -28,7 +28,7 @@ public class IslandSettingsCommand extends CompositeCommand {
|
|||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
// Settings are only shown if you are in the right world
|
// Settings are only shown if you are in the right world
|
||||||
if (Util.getWorld(user.getWorld()).equals(getWorld())) {
|
if (Util.getWorld(user.getWorld()).equals(getWorld())) {
|
||||||
SettingsPanel.openPanel(getPlugin(), user, Flag.Type.PROTECTION, getWorld());
|
SettingsPanel.openPanel(getPlugin(), user, Flag.Type.PROTECTION, getWorld(), 0);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
user.sendMessage("general.errors.wrong-world");
|
user.sendMessage("general.errors.wrong-world");
|
||||||
|
@ -29,11 +29,17 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
|
|||||||
if (object instanceof MemorySection) {
|
if (object instanceof MemorySection) {
|
||||||
MemorySection section = (MemorySection) object;
|
MemorySection section = (MemorySection) object;
|
||||||
for (String key : section.getKeys(false)) {
|
for (String key : section.getKeys(false)) {
|
||||||
result.put(BentoBox.getInstance().getFlagsManager().getFlagByID(key), section.getInt(key));
|
Flag flag = BentoBox.getInstance().getFlagsManager().getFlagByID(key);
|
||||||
|
if (flag != null) {
|
||||||
|
result.put(flag, section.getInt(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Entry<String, Integer> en : ((Map<String, Integer>)object).entrySet()) {
|
for (Entry<String, Integer> en : ((Map<String, Integer>)object).entrySet()) {
|
||||||
result.put(BentoBox.getInstance().getFlagsManager().getFlagByID(en.getKey()), en.getValue());
|
Flag flag = BentoBox.getInstance().getFlagsManager().getFlagByID(en.getKey());
|
||||||
|
if (flag != null) {
|
||||||
|
result.put(flag, en.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -48,7 +54,9 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
|
|||||||
}
|
}
|
||||||
Map<Flag, Integer> flags = (Map<Flag, Integer>)object;
|
Map<Flag, Integer> flags = (Map<Flag, Integer>)object;
|
||||||
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
||||||
result.put(en.getKey().getID(), en.getValue());
|
if (en != null && en.getKey() != null) {
|
||||||
|
result.put(en.getKey().getID(), en.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package world.bentobox.bentobox.listeners.flags;
|
package world.bentobox.bentobox.listeners.flags;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.TropicalFish;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
@ -37,6 +40,7 @@ public class BucketListener extends FlagListener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onBucketFill(final PlayerBucketFillEvent e) {
|
public void onBucketFill(final PlayerBucketFillEvent e) {
|
||||||
|
Bukkit.getLogger().info("DEBUG: " + e.getEventName());
|
||||||
// Check filling of various liquids
|
// Check filling of various liquids
|
||||||
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA))) {
|
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA))) {
|
||||||
return;
|
return;
|
||||||
@ -51,4 +55,12 @@ public class BucketListener extends FlagListener {
|
|||||||
checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET);
|
checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onTropicalFishSc(final PlayerInteractEntityEvent e) {
|
||||||
|
if (e.getRightClicked() instanceof TropicalFish && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WATER_BUCKET) && (!checkIsland(e, e.getRightClicked().getLocation(), Flags.FISH_SCOOPING))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -91,6 +91,7 @@ public class Flags {
|
|||||||
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
|
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
|
||||||
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
|
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
|
||||||
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
|
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
|
||||||
|
public static final Flag FISH_SCOOPING = new FlagBuilder().id("FISH_SCOOPING").allowedByDefault(false).icon(Material.TROPICAL_FISH_BUCKET).build();
|
||||||
|
|
||||||
// Chorus Fruit and Enderpearls
|
// Chorus Fruit and Enderpearls
|
||||||
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
|
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package world.bentobox.bentobox.panels;
|
package world.bentobox.bentobox.panels;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -29,7 +31,7 @@ public class SettingsPanel {
|
|||||||
* @param flagType - initial view
|
* @param flagType - initial view
|
||||||
* @param world - world
|
* @param world - world
|
||||||
*/
|
*/
|
||||||
public static void openPanel(BentoBox plugin, User user, Flag.Type flagType, World world) {
|
public static void openPanel(BentoBox plugin, User user, Flag.Type flagType, World world, int page) {
|
||||||
String friendlyWorldName = plugin.getIWM().getFriendlyName(world);
|
String friendlyWorldName = plugin.getIWM().getFriendlyName(world);
|
||||||
// Create the panel
|
// Create the panel
|
||||||
PanelBuilder panelBuilder = new PanelBuilder()
|
PanelBuilder panelBuilder = new PanelBuilder()
|
||||||
@ -38,8 +40,35 @@ public class SettingsPanel {
|
|||||||
|
|
||||||
setupHeader(user, panelBuilder, flagType, world, friendlyWorldName);
|
setupHeader(user, panelBuilder, flagType, world, friendlyWorldName);
|
||||||
|
|
||||||
plugin.getFlagsManager().getFlags().stream().filter(f -> f.getType().equals(flagType))
|
// Get a list of flags of the correct type and sort by the translated names
|
||||||
.sorted(Comparator.comparing(Flag::getID)).forEach((f -> panelBuilder.item(f.toPanelItem(plugin, user))));
|
List<Flag> flags = plugin.getFlagsManager().getFlags().stream().filter(f -> f.getType().equals(flagType))
|
||||||
|
.sorted(Comparator.comparing(Flag::getID, (s1, s2) -> {
|
||||||
|
String s1Translation = user.getTranslation(plugin.getFlagsManager().getFlagByID(s1).getNameReference());
|
||||||
|
String s2Translation = user.getTranslation(plugin.getFlagsManager().getFlagByID(s2).getNameReference());
|
||||||
|
return s1Translation.compareTo(s2Translation);
|
||||||
|
}))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// Use paging
|
||||||
|
flags.stream().skip(page * 43).limit(page * 43 + 43).forEach((f -> panelBuilder.item(f.toPanelItem(plugin, user))));
|
||||||
|
// Add forward and backward icons
|
||||||
|
if (page > 0) {
|
||||||
|
// Previous page icon
|
||||||
|
panelBuilder.item(new PanelItemBuilder().icon(Material.SIGN).name(user.getTranslation(PROTECTION_PANEL + "previous")).clickHandler((panel, user1, clickType, slot1) -> {
|
||||||
|
openPanel(BentoBox.getInstance(), user, flagType, world, page - 1);
|
||||||
|
return true;
|
||||||
|
}).build());
|
||||||
|
}
|
||||||
|
if ((page + 1) * 44 < flags.size()) {
|
||||||
|
// Next page icon
|
||||||
|
panelBuilder.item(new PanelItemBuilder().icon(Material.SIGN).name(user.getTranslation(PROTECTION_PANEL + "next")).clickHandler((panel, user1, clickType, slot1) -> {
|
||||||
|
openPanel(BentoBox.getInstance(), user, flagType, world, page + 1);
|
||||||
|
return true;
|
||||||
|
}).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Show it to the player
|
// Show it to the player
|
||||||
panelBuilder.build().open(user);
|
panelBuilder.build().open(user);
|
||||||
@ -55,7 +84,7 @@ public class SettingsPanel {
|
|||||||
.glow(flagType.equals(currentFlagType))
|
.glow(flagType.equals(currentFlagType))
|
||||||
.clickHandler((panel, user1, clickType, slot1) -> {
|
.clickHandler((panel, user1, clickType, slot1) -> {
|
||||||
if (!flagType.equals(currentFlagType)) {
|
if (!flagType.equals(currentFlagType)) {
|
||||||
openPanel(BentoBox.getInstance(), user, flagType, world);
|
openPanel(BentoBox.getInstance(), user, flagType, world, 0);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
|
@ -530,6 +530,12 @@ protection:
|
|||||||
description: "Toggle spread"
|
description: "Toggle spread"
|
||||||
name: "Fire spread"
|
name: "Fire spread"
|
||||||
hint: "No fire spread allowed"
|
hint: "No fire spread allowed"
|
||||||
|
FISH_SCOOPING:
|
||||||
|
description: |
|
||||||
|
&aAllow scooping of
|
||||||
|
&atropical fish
|
||||||
|
name: "Fish Scooping"
|
||||||
|
hint: "No scooping of tropical fish"
|
||||||
FURNACE:
|
FURNACE:
|
||||||
description: "Toggle use"
|
description: "Toggle use"
|
||||||
name: "Furnace"
|
name: "Furnace"
|
||||||
@ -691,6 +697,8 @@ protection:
|
|||||||
spawn-protected: "&cSpawn protected: [description]"
|
spawn-protected: "&cSpawn protected: [description]"
|
||||||
|
|
||||||
panel:
|
panel:
|
||||||
|
next: "Next Page"
|
||||||
|
previous: "Previous Page"
|
||||||
PROTECTION:
|
PROTECTION:
|
||||||
title: "Protection"
|
title: "Protection"
|
||||||
description: |-
|
description: |-
|
||||||
|
Loading…
Reference in New Issue
Block a user