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

Bug fixing session #253

Merged
merged 11 commits into from
Jun 13, 2024
15 changes: 11 additions & 4 deletions TestServer/plugins/TF_PrisonEscape/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ PrisonersSecretPassagesLocation:
Z: 8
Value:
X: 0
Y: 83
Y: 82
Z: 5
"2":
Key:
Expand All @@ -150,7 +150,7 @@ PrisonersSecretPassagesLocation:
Z: 2
Value:
X: 0
Y: 83
Y: 82
Z: 0
"3":
Key:
Expand All @@ -159,7 +159,7 @@ PrisonersSecretPassagesLocation:
Z: -4
Value:
X: 0
Y: 83
Y: 82
Z: -5
"4":
Key:
Expand All @@ -168,7 +168,7 @@ PrisonersSecretPassagesLocation:
Z: -10
Value:
X: 0
Y: 83
Y: 82
Z: -10
"5":
Key:
Expand Down Expand Up @@ -1256,6 +1256,7 @@ ChestsContents:
Stick: 0.005
PlasticPlate: 0.01
Copper: 0.01
GoldBar: 0.01
Battery: 0.005
NotePart: 0.01
EnergyDrink: 0.1
Expand All @@ -1269,6 +1270,7 @@ ChestsContents:
Stick: 0.005
PlasticPlate: 0.01
Copper: 0.01
GoldBar: 0.01
Battery: 0.005
NotePart: 0.01
EnergyDrink: 0.1
Expand All @@ -1282,6 +1284,7 @@ ChestsContents:
Stick: 0.005
PlasticPlate: 0.01
Copper: 0.05
GoldBar: 0.03
Antena: 0.025
Battery: 0.025
NotePart: 0.05
Expand All @@ -1299,6 +1302,7 @@ ChestsContents:
Stick: 0.025
PlasticPlate: 0.01
Copper: 0.01
GoldBar: 0.01
Battery: 0.005
NotePart: 0.01
EnergyDrink: 0.1
Expand All @@ -1313,6 +1317,7 @@ ChestsContents:
PlasticPlate: 0.05
MetalPlate: 0.01
Copper: 0.01
GoldBar: 0.01
Battery: 0.005
NotePart: 0.01
EnergyDrink: 0.1
Expand All @@ -1328,6 +1333,7 @@ ChestsContents:
PlasticPlate: 0.1
MetalPlate: 0.01
Copper: 0.01
GoldBar: 0.01
Battery: 0.005
NotePart: 0.01
EnergyDrink: 0.1
Expand All @@ -1341,6 +1347,7 @@ ChestsContents:
Stick: 0.005
PlasticPlate: 0.01
Copper: 0.01
GoldBar: 0.01
Battery: 0.005
NotePart: 0.01
EnergyDrink: 0.1
Expand Down
1 change: 1 addition & 0 deletions TestServer/plugins/TF_PrisonEscape/languages/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Messages:
TradeRequestSent: "&eTrade request sent to &b{PLAYER}&e."
TradeRequestReceived: "&eYou received a trade request. Shift+Click &b{PLAYER} &eto accept. You have &b{TIME} seconds"
CraftingItemsMissing: "&cYou are missing some items required to craft that item."
CodeFound: "&eSomeone found the main door code."
Announcements:
GameStarting:
- "&6==================================="
Expand Down
57 changes: 30 additions & 27 deletions src/main/java/net/tiagofar78/prisonescape/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import net.tiagofar78.prisonescape.game.PEGame;
import net.tiagofar78.prisonescape.items.FunctionalItem;
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.items.ItemFactory;
import net.tiagofar78.prisonescape.managers.ConfigManager;
import net.tiagofar78.prisonescape.managers.GameManager;
import net.tiagofar78.prisonescape.menus.ClickReturnAction;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
Expand All @@ -25,6 +23,7 @@
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
Expand All @@ -38,13 +37,12 @@
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class Events implements Listener {

private static final EntityType[] ALLOWED_MOBS =
{EntityType.PRIMED_TNT, EntityType.PAINTING, EntityType.ARMOR_STAND};
{EntityType.PRIMED_TNT, EntityType.PAINTING, EntityType.ARMOR_STAND, EntityType.ITEM_FRAME};

@EventHandler
public void playerMove(PlayerMoveEvent e) {
Expand Down Expand Up @@ -156,35 +154,20 @@ public void playerClickInventory(InventoryClickEvent e) {
}

Player player = (Player) e.getWhoClicked();
boolean isPlayerInv = false;
if (e.getClickedInventory().getType() == InventoryType.PLAYER) {
Inventory topInv = e.getView().getTopInventory();
if (topInv == null) {
e.setCancelled(true);
return;
}
boolean isPlayerInv = e.getClickedInventory().getType() == InventoryType.PLAYER;

if (e.getCurrentItem() != null && e.getCurrentItem().getType() == Material.BLACK_STAINED_GLASS_PANE) {
if (isPlayerInv && e.getAction() == InventoryAction.DROP_ONE_SLOT) {
if (game.playerDropItem(player.getName(), e.getSlot()) == -1) {
e.setCancelled(true);
return;
}

if (e.getAction() == InventoryAction.DROP_ALL_SLOT || e.getAction() == InventoryAction.DROP_ONE_SLOT) {
int slot = e.getSlot();
if (game.playerDropItem(player.getName(), slot) == -1) {
e.setCancelled(true);
}
return;
}

isPlayerInv = true;
return;
}

ItemStack cursor = e.getCursor();
ItemStack current = e.getCurrentItem();

Item item = ItemFactory.createItem(e.getCursor());
ClickReturnAction returnAction = game.playerClickMenu(player.getName(), e.getSlot(), item, isPlayerInv);
ClickReturnAction returnAction = game.playerClickMenu(player.getName(), e.getSlot(), isPlayerInv);
if (returnAction == ClickReturnAction.IGNORE) {
return;
}
Expand Down Expand Up @@ -269,6 +252,17 @@ public void onBlockBreak(BlockBreakEvent event) {
}
}

@EventHandler
public void onBlockHangingBreak(HangingBreakEvent e) {
EntityType type = e.getEntity().getType();
for (EntityType mobType : ALLOWED_MOBS) {
if (mobType == type) {
e.setCancelled(true);
break;
}
}
}

@EventHandler
public void onExplosion(EntityExplodeEvent e) {
if (!e.getEntity().getWorld().getName().equals(ConfigManager.getInstance().getWorldName())) {
Expand All @@ -295,7 +289,8 @@ public void onPlayerInteractWithPlayer(PlayerInteractEntityEvent e) {

@EventHandler
public void onPlayerCombat(EntityDamageByEntityEvent e) {
if (GameManager.getGame() == null) {
PEGame game = GameManager.getGame();
if (game == null) {
return;
}

Expand All @@ -304,10 +299,18 @@ public void onPlayerCombat(EntityDamageByEntityEvent e) {
return;
}

EntityType type = e.getEntity().getType();
for (EntityType mobType : ALLOWED_MOBS) {
if (mobType == type) {
e.setCancelled(true);
break;
}
}

Player pAttacker = (Player) eAttacker;

@SuppressWarnings("deprecation")
Item item = ItemFactory.createItem(pAttacker.getItemInHand());
String attackerName = pAttacker.getName();
Item item = game.getPEPlayer(attackerName).getItemAt(pAttacker.getInventory().getHeldItemSlot());

if (item.isFunctional()) {
((FunctionalItem) item).use(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void teleport(PEPlayer player, Location loc) {
return;
}

bukkitPlayer.teleport(loc.add(0, CENTER_OF_BLOCK, 0));
bukkitPlayer.teleport(loc.clone().add(CENTER_OF_BLOCK, 0, CENTER_OF_BLOCK));
}

}
10 changes: 7 additions & 3 deletions src/main/java/net/tiagofar78/prisonescape/game/PEGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,18 +710,18 @@ public void playerCloseMenu(String playerName) {
player.closeMenu();
}

public ClickReturnAction playerClickMenu(String playerName, int slot, Item itemHeld, boolean clickedPlayerInv) {
public ClickReturnAction playerClickMenu(String playerName, int slot, boolean clickedPlayerInv) {
PEPlayer player = getPEPlayer(playerName);
if (player == null) {
return ClickReturnAction.IGNORE;
}

Clickable menu = player.getOpenedMenu();
if (menu == null) {
return ClickReturnAction.IGNORE;
return ClickReturnAction.NOTHING;
}

return menu.click(player, slot, itemHeld, clickedPlayerInv);
return menu.click(player, slot, clickedPlayerInv);
}

public void playerSneak(String playerName) {
Expand Down Expand Up @@ -1207,4 +1207,8 @@ public void findDoorCode() {
_hasDoorCode = true;
}

public void changeDoorCode() {
_hasDoorCode = false;
}

}
9 changes: 9 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ private void closeInventoryView() {
player.closeInventory();
}

public void setCursorItem(ItemStack item) {
Player player = getBukkitPlayer();
if (player == null) {
return;
}

player.setItemOnCursor(item);
}

public void playSound(Sound sound) {
Player player = getBukkitPlayer();
if (player == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private Item getRandomItem() {
}

@Override
public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv) {
public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) {
if (clickedPlayerInv) {
return ClickReturnAction.NOTHING;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Vault implements Clickable {

private List<Item> _nonHiddenContents;
private List<Item> _hiddenContents;
private Item _cursorItem;

private Prisoner _owner;

Expand All @@ -43,6 +44,7 @@ public class Vault implements Clickable {
public Vault(Prisoner owner, Location location) {
_nonHiddenContents = createContentsList(NON_HIDDEN_SIZE);
_hiddenContents = createContentsList(HIDDEN_SIZE);
_cursorItem = new NullItem();

_owner = owner;

Expand Down Expand Up @@ -99,19 +101,22 @@ public int search() {

private void clearContents(List<Item> contents, int size) {
for (int i = 0; i < size; i++) {
contents.set(i, null);
contents.set(i, new NullItem());
}
}

@Override
public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv) {
public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) {
if (clickedPlayerInv) {
int index = player.convertToInventoryIndex(slot);
if (index == -1) {
return ClickReturnAction.NOTHING;
}

player.setItem(index, itemHeld);
Item currentItem = player.getItemsInInventory().get(index);

player.setItem(index, _cursorItem);
_cursorItem = currentItem;
return ClickReturnAction.CHANGE_HOLD_AND_SELECTED;
}

Expand All @@ -122,10 +127,46 @@ public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean

boolean isHidden = isHiddenIndex(slot);

setItem(isHidden, itemIndex, itemHeld);
Item currentItem = isHidden ? _hiddenContents.get(itemIndex) : _nonHiddenContents.get(itemIndex);

setItem(isHidden, itemIndex, _cursorItem);
_cursorItem = currentItem;
return ClickReturnAction.CHANGE_HOLD_AND_SELECTED;
}

@Override
public void close(PEPlayer player) {
player.setCursorItem(null);

if (_cursorItem.equals(new NullItem())) {
return;
}

if (player.giveItem(_cursorItem) != -1) {
_cursorItem = new NullItem();
player.updateInventory();
return;
}

for (int i = 0; i < _hiddenContents.size(); i++) {
if (_hiddenContents.get(i).equals(new NullItem())) {
setItem(false, i, _cursorItem);
_cursorItem = new NullItem();
return;
}
}

for (int i = 0; i < _nonHiddenContents.size(); i++) {
if (_nonHiddenContents.get(i).equals(new NullItem())) {
setItem(true, i, _cursorItem);
_cursorItem = new NullItem();
return;
}
}

throw new RuntimeException("There are more items in inventory + vault now than when it was opened");
}

private int convertToIndex(int slot) {
for (int i = 0; i < NON_HIDDEN_ITEMS_INDEXES.length; i++) {
if (NON_HIDDEN_ITEMS_INDEXES[i] == slot) {
Expand Down Expand Up @@ -156,7 +197,7 @@ private void createWorldVault(Location location) {
}

private void createWorldSignAboveVault(Location location, String text) {
Block block = location.getBlock();
Block block = location.clone().add(0, 1, 0).getBlock();
block.setType(Material.OAK_WALL_SIGN);

rotate(block);
Expand All @@ -179,7 +220,7 @@ public void deleteVaultAndRespectiveSignFromWorld() {
Location signLocation = _location.clone().add(0, 1, 0);

vaultLocation.getBlock().setType(Material.AIR);
signLocation.clone().add(0, 1, 0).getBlock().setType(Material.AIR);
signLocation.getBlock().setType(Material.AIR);
}

@Override
Expand Down
Loading
Loading