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