Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed bukkit actions from managers #19

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tiagofar78.prisonescape.managers;
package net.tiagofar78.prisonescape.bukkit;

import net.tiagofar78.prisonescape.game.PrisonEscapeItem;

Expand All @@ -7,11 +7,11 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.Inventory;

public class InventoryManager {
public class BukkitInventory {

Inventory _inventory;
private Inventory _inventory;

public InventoryManager(Inventory inventory) {
public BukkitInventory(Inventory inventory) {
this._inventory = inventory;
}

Expand Down Expand Up @@ -75,19 +75,19 @@ private ItemStack convertToItemStack(PrisonEscapeItem item) {
return itemStack;
}

public void addItemToInventory(int slot, PrisonEscapeItem item) {
public void addItem(int slot, PrisonEscapeItem item) {
_inventory.setItem(slot, this.convertToItemStack(item));
}

public void addItemToInventory(int slot, ItemStack item) {
public void addItem(int slot, ItemStack item) {
_inventory.setItem(slot, item);
}

public void deleteItemFromInventory(int slot) {
public void deleteItem(int slot) {
_inventory.clear(slot);
}

public void clearInventory() {
public void clear() {
_inventory.clear();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tiagofar78.prisonescape.managers;
package net.tiagofar78.prisonescape.bukkit;

import java.util.List;

Expand All @@ -7,7 +7,7 @@

import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;

public class MessageManager {
public class BukkitMessageSender {

public static void sendChatMessage(PrisonEscapePlayer player, String message) {
Player bukkitPlayer = Bukkit.getPlayer(player.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.tiagofar78.prisonescape.bukkit;

import org.bukkit.Bukkit;

import net.tiagofar78.prisonescape.PrisonEscape;

public class BukkitScheduler {

public static void runSchedulerLater(Runnable runnable, long delay) {
Bukkit.getScheduler().runTaskLater(PrisonEscape.getPrisonEscape(), runnable, delay);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tiagofar78.prisonescape.managers;
package net.tiagofar78.prisonescape.bukkit;

import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -7,8 +7,9 @@

import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;
import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation;
import net.tiagofar78.prisonescape.managers.ConfigManager;

public class TeleportManager {
public class BukkitTeleporter {

private static final double CENTER_OF_BLOCK = 0.5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import java.util.Collections;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import net.tiagofar78.prisonescape.PrisonEscape;
import net.tiagofar78.prisonescape.bukkit.BukkitScheduler;
import net.tiagofar78.prisonescape.bukkit.BukkitTeleporter;
import net.tiagofar78.prisonescape.game.phases.Phase;
import net.tiagofar78.prisonescape.game.phases.Waiting;
import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonBuilding;
import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation;
import net.tiagofar78.prisonescape.managers.ConfigManager;
import net.tiagofar78.prisonescape.managers.TeleportManager;

public class PrisonEscapeGame {

Expand Down Expand Up @@ -155,7 +154,7 @@ private void startDay() {

_prison.reloadChests();

Bukkit.getScheduler().runTaskLater(PrisonEscape.getPrisonEscape(), new Runnable() {
BukkitScheduler.runSchedulerLater(new Runnable() {

@Override
public void run() {
Expand All @@ -171,7 +170,7 @@ private void startNight() {

_dayPeriod = DayPeriod.NIGHT;

Bukkit.getScheduler().runTaskLater(PrisonEscape.getPrisonEscape(), new Runnable() {
BukkitScheduler.runSchedulerLater(new Runnable() {

@Override
public void run() {
Expand Down Expand Up @@ -256,11 +255,11 @@ else if (item == PrisonEscapeItem.SEARCH) {
// ########################################

private void arrestPlayer(PrisonEscapePlayer arrested, PrisonEscapePlayer arrester) {
TeleportManager.teleport(arrested, _prison.getSolitaryLocation());
BukkitTeleporter.teleport(arrested, _prison.getSolitaryLocation());

// TODO warn players

Bukkit.getScheduler().runTaskLater(PrisonEscape.getPrisonEscape(), new Runnable() {
BukkitScheduler.runSchedulerLater(new Runnable() {

@Override
public void run() {
Expand All @@ -273,11 +272,11 @@ public void run() {
// TODO warn arrested

if (_dayPeriod == DayPeriod.DAY) {
TeleportManager.teleport(arrested, _prison.getSolitaryExitLocation());
BukkitTeleporter.teleport(arrested, _prison.getSolitaryExitLocation());
}
else if (_dayPeriod == DayPeriod.NIGHT) {
int playerIndex = _prisionersTeam.getPlayerIndex(arrested);
TeleportManager.teleport(arrested, _prison.getPlayerCellLocation(playerIndex));
BukkitTeleporter.teleport(arrested, _prison.getPlayerCellLocation(playerIndex));
}
}
}, TICKS_PER_SECOND * _settings.getSecondsInSolitary());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import net.tiagofar78.prisonescape.bukkit.BukkitInventory;
import net.tiagofar78.prisonescape.dataobjects.ItemProbability;
import net.tiagofar78.prisonescape.game.PrisonEscapeItem;
import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;
import net.tiagofar78.prisonescape.managers.ConfigManager;
import net.tiagofar78.prisonescape.managers.InventoryManager;

public class Chest {

Expand All @@ -26,7 +26,7 @@ public class Chest {
private List<Integer> _contentsIndexes;
private Hashtable<Integer, PrisonEscapeItem> _contents;
private List<ItemProbability> _itemsProbability;
private InventoryManager _inventoryManager;
private BukkitInventory _inventoryManager;
private Inventory _inventory;

protected Chest(int size, List<ItemProbability> itemsProbability) {
Expand All @@ -39,14 +39,14 @@ protected Chest(int size, List<ItemProbability> itemsProbability) {
ConfigManager config = ConfigManager.getInstance();
this._inventory = Bukkit.createInventory(null, lines * SLOTS_PER_LINE, config.getContainerName());

this._inventoryManager = new InventoryManager(_inventory);
this._inventoryManager = new BukkitInventory(_inventory);

reload();
}

public void reload() {
_contents.clear();
_inventoryManager.clearInventory();
_inventoryManager.clear();

for (int index : _contentsIndexes) {
_contents.put(index, getRandomItem());
Expand All @@ -72,11 +72,11 @@ private PrisonEscapeItem getRandomItem() {
public void buildInventory() {
int lines = 3;
for (int i = 0; i < lines * SLOTS_PER_LINE; i++) {
_inventoryManager.addItemToInventory(i, GRAY_PANEL);
_inventoryManager.addItem(i, GRAY_PANEL);
}

for (int slot : _contentsIndexes) {
_inventoryManager.addItemToInventory(slot, _contents.get(slot));
_inventoryManager.addItem(slot, _contents.get(slot));
}
}

Expand All @@ -99,7 +99,7 @@ public void playerClickEvent(InventoryClickEvent e, PrisonEscapePlayer player) {
}
else if (returnCode == 0) {
_contents.put(slot, null);
_inventoryManager.deleteItemFromInventory(slot);
_inventoryManager.deleteItem(slot);
}

}
Expand Down