mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Encapsulate fields
This commit is contained in:
parent
c55f2945ac
commit
4789327378
@ -49,11 +49,11 @@ import java.util.stream.IntStream;
|
|||||||
@Singleton public class BukkitInventoryUtil extends InventoryUtil {
|
@Singleton public class BukkitInventoryUtil extends InventoryUtil {
|
||||||
|
|
||||||
@Override public void open(PlotInventory inv) {
|
@Override public void open(PlotInventory inv) {
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9,
|
Inventory inventory = Bukkit.createInventory(null, inv.getSize() * 9,
|
||||||
ChatColor.translateAlternateColorCodes('&', inv.getTitle()));
|
ChatColor.translateAlternateColorCodes('&', inv.getTitle()));
|
||||||
PlotItemStack[] items = inv.getItems();
|
PlotItemStack[] items = inv.getItems();
|
||||||
for (int i = 0; i < inv.size * 9; i++) {
|
for (int i = 0; i < inv.getSize() * 9; i++) {
|
||||||
PlotItemStack item = items[i];
|
PlotItemStack item = items[i];
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
inventory.setItem(i, getItem(item));
|
inventory.setItem(i, getItem(item));
|
||||||
@ -66,12 +66,12 @@ import java.util.stream.IntStream;
|
|||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||||
bp.player.closeInventory();
|
bp.player.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||||
InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
@ -84,18 +84,18 @@ import java.util.stream.IntStream;
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ItemStack stack = new ItemStack(BukkitAdapter.adapt(item.getType()), item.amount);
|
ItemStack stack = new ItemStack(BukkitAdapter.adapt(item.getType()), item.getAmount());
|
||||||
ItemMeta meta = null;
|
ItemMeta meta = null;
|
||||||
if (item.name != null) {
|
if (item.getName() != null) {
|
||||||
meta = stack.getItemMeta();
|
meta = stack.getItemMeta();
|
||||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', item.name));
|
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', item.getName()));
|
||||||
}
|
}
|
||||||
if (item.lore != null) {
|
if (item.getLore() != null) {
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
meta = stack.getItemMeta();
|
meta = stack.getItemMeta();
|
||||||
}
|
}
|
||||||
List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
for (String entry : item.lore) {
|
for (String entry : item.getLore()) {
|
||||||
lore.add(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(BukkitUtil.MINI_MESSAGE.deserialize(entry)));
|
lore.add(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(BukkitUtil.MINI_MESSAGE.deserialize(entry)));
|
||||||
}
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
@ -141,7 +141,7 @@ import java.util.stream.IntStream;
|
|||||||
if (!plotInventory.isOpen()) {
|
if (!plotInventory.isOpen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BukkitPlayer bp = (BukkitPlayer) plotInventory.player;
|
BukkitPlayer bp = (BukkitPlayer) plotInventory.getPlayer();
|
||||||
InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
if (plotInventory.isOpen()) {
|
if (plotInventory.isOpen()) {
|
||||||
if (opened.getType() == InventoryType.CRAFTING) {
|
if (opened.getType() == InventoryType.CRAFTING) {
|
||||||
|
@ -87,27 +87,27 @@ public class Music extends SubCommand {
|
|||||||
.createFlagInstance(item.getType());
|
.createFlagInstance(item.getType());
|
||||||
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(plotFlag, plot);
|
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(plotFlag, plot);
|
||||||
if (event.getEventResult() == Result.DENY) {
|
if (event.getEventResult() == Result.DENY) {
|
||||||
player.sendMessage(
|
getPlayer().sendMessage(
|
||||||
TranslatableCaption.of("events.event_denied"),
|
TranslatableCaption.of("events.event_denied"),
|
||||||
Template.of("value", "Music removal"));
|
Template.of("value", "Music removal"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plot.removeFlag(event.getFlag());
|
plot.removeFlag(event.getFlag());
|
||||||
player.sendMessage(TranslatableCaption.of("flag.flag_removed"));
|
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_removed"));
|
||||||
} else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) {
|
} else if (item.getName().toLowerCase(Locale.ENGLISH).contains("disc")) {
|
||||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
|
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
|
||||||
.createFlagInstance(item.getType());
|
.createFlagInstance(item.getType());
|
||||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||||
if (event.getEventResult() == Result.DENY) {
|
if (event.getEventResult() == Result.DENY) {
|
||||||
player.sendMessage(
|
getPlayer().sendMessage(
|
||||||
TranslatableCaption.of("events.event_denied"),
|
TranslatableCaption.of("events.event_denied"),
|
||||||
Template.of("value", "Music addition"));
|
Template.of("value", "Music addition"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plot.setFlag(event.getFlag());
|
plot.setFlag(event.getFlag());
|
||||||
player.sendMessage(TranslatableCaption.of("flag.flag_added"));
|
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_added"));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("flag.flag_not_added"));
|
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_not_added"));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -160,19 +160,19 @@ public class Rate extends SubCommand {
|
|||||||
if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) {
|
if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) {
|
||||||
int rV = rating.getValue();
|
int rV = rating.getValue();
|
||||||
PlotRateEvent event = Rate.this.eventDispatcher
|
PlotRateEvent event = Rate.this.eventDispatcher
|
||||||
.callRating(this.player, plot, new Rating(rV));
|
.callRating(this.getPlayer(), plot, new Rating(rV));
|
||||||
if (event.getRating() != null) {
|
if (event.getRating() != null) {
|
||||||
plot.addRating(this.player.getUUID(), event.getRating());
|
plot.addRating(this.getPlayer().getUUID(), event.getRating());
|
||||||
player.sendMessage(
|
getPlayer().sendMessage(
|
||||||
TranslatableCaption.of("ratings.rating_applied"),
|
TranslatableCaption.of("ratings.rating_applied"),
|
||||||
Template.of("plot", plot.getId().toString())
|
Template.of("plot", plot.getId().toString())
|
||||||
);
|
);
|
||||||
if (Permissions
|
if (Permissions
|
||||||
.hasPermission(this.player, Permission.PERMISSION_COMMENT)) {
|
.hasPermission(this.getPlayer(), Permission.PERMISSION_COMMENT)) {
|
||||||
Command command =
|
Command command =
|
||||||
MainCommand.getInstance().getCommand(Comment.class);
|
MainCommand.getInstance().getCommand(Comment.class);
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
player.sendMessage(
|
getPlayer().sendMessage(
|
||||||
TranslatableCaption.of("tutorial.comment_this"),
|
TranslatableCaption.of("tutorial.comment_this"),
|
||||||
Template.of("plot", "/plot rate")
|
Template.of("plot", "/plot rate")
|
||||||
);
|
);
|
||||||
|
@ -155,7 +155,7 @@ public class ComponentPresetManager {
|
|||||||
final int size = (int) Math.ceil((double) allowedPresets.size() / 9.0D);
|
final int size = (int) Math.ceil((double) allowedPresets.size() / 9.0D);
|
||||||
final PlotInventory plotInventory = new PlotInventory(this.inventoryUtil, player, size, this.guiName) {
|
final PlotInventory plotInventory = new PlotInventory(this.inventoryUtil, player, size, this.guiName) {
|
||||||
@Override public boolean onClick(final int index) {
|
@Override public boolean onClick(final int index) {
|
||||||
if (!player.getCurrentPlot().equals(plot)) {
|
if (!getPlayer().getCurrentPlot().equals(plot)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,28 +169,28 @@ public class ComponentPresetManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (plot.getRunning() > 0) {
|
if (plot.getRunning() > 0) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
|
getPlayer().sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pattern pattern = PatternUtil.parse(null, componentPreset.getPattern(), false);
|
final Pattern pattern = PatternUtil.parse(null, componentPreset.getPattern(), false);
|
||||||
if (pattern == null) {
|
if (pattern == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("preset.preset_invalid"));
|
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_invalid"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (componentPreset.getCost() > 0.0D && econHandler != null && plot.getArea().useEconomy()) {
|
if (componentPreset.getCost() > 0.0D && econHandler != null && plot.getArea().useEconomy()) {
|
||||||
if (econHandler.getMoney(player) < componentPreset.getCost()) {
|
if (econHandler.getMoney(getPlayer()) < componentPreset.getCost()) {
|
||||||
player.sendMessage(TranslatableCaption.of("preset.preset_cannot_afford"));
|
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford"));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
econHandler.withdrawMoney(player, componentPreset.getCost());
|
econHandler.withdrawMoney(getPlayer(), componentPreset.getCost());
|
||||||
player.sendMessage(TranslatableCaption.of("economy.removed_balance"),
|
getPlayer().sendMessage(TranslatableCaption.of("economy.removed_balance"),
|
||||||
Template.of("money", componentPreset.getCost() + ""));
|
Template.of("money", componentPreset.getCost() + ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BackupManager.backup(player, plot, () -> {
|
BackupManager.backup(getPlayer(), plot, () -> {
|
||||||
plot.addRunning();
|
plot.addRunning();
|
||||||
QueueCoordinator queue = plot.getArea().getQueue();
|
QueueCoordinator queue = plot.getArea().getQueue();
|
||||||
for (Plot current : plot.getConnectedPlots()) {
|
for (Plot current : plot.getConnectedPlots()) {
|
||||||
@ -198,7 +198,7 @@ public class ComponentPresetManager {
|
|||||||
}
|
}
|
||||||
queue.setCompleteTask(plot::removeRunning);
|
queue.setCompleteTask(plot::removeRunning);
|
||||||
queue.enqueue();
|
queue.enqueue();
|
||||||
player.sendMessage(TranslatableCaption.of("working.generating_component"));
|
getPlayer().sendMessage(TranslatableCaption.of("working.generating_component"));
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ public class PlotInventory {
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotInventory.class.getSimpleName());
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotInventory.class.getSimpleName());
|
||||||
|
|
||||||
public final PlotPlayer<?> player;
|
private final PlotPlayer<?> player;
|
||||||
public final int size;
|
private final int size;
|
||||||
private final PlotItemStack[] items;
|
private final PlotItemStack[] items;
|
||||||
private String title;
|
private String title;
|
||||||
private boolean open = false;
|
private boolean open = false;
|
||||||
@ -88,9 +88,9 @@ public class PlotInventory {
|
|||||||
if (this.title == null) {
|
if (this.title == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!hasPlotInventoryOpen(player)) {
|
if (!hasPlotInventoryOpen(getPlayer())) {
|
||||||
this.open = true;
|
this.open = true;
|
||||||
setPlotInventoryOpen(player, this);
|
setPlotInventoryOpen(getPlayer(), this);
|
||||||
this.inventoryUtil.open(this);
|
this.inventoryUtil.open(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ public class PlotInventory {
|
|||||||
if (this.title == null) {
|
if (this.title == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
removePlotInventoryOpen(player);
|
removePlotInventoryOpen(getPlayer());
|
||||||
this.inventoryUtil.close(this);
|
this.inventoryUtil.close(this);
|
||||||
this.open = false;
|
this.open = false;
|
||||||
}
|
}
|
||||||
@ -140,4 +140,11 @@ public class PlotInventory {
|
|||||||
return this.open;
|
return this.open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlotPlayer<?> getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
|
|||||||
|
|
||||||
public class PlotItemStack {
|
public class PlotItemStack {
|
||||||
|
|
||||||
public final int amount;
|
private final int amount;
|
||||||
public final String name;
|
private final String name;
|
||||||
public final String[] lore;
|
private final String[] lore;
|
||||||
private final ItemType type;
|
private final ItemType type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,10 +69,22 @@ public class PlotItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getBlockState() {
|
public BlockState getBlockState() {
|
||||||
return type.getBlockType().getDefaultState();
|
return getType().getBlockType().getDefaultState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemType getType() {
|
public ItemType getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getLore() {
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user