Skip to content

Commit

Permalink
Fix: Remove door from shop, after breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueMB committed Feb 5, 2024
1 parent 4da80a1 commit 21407f4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 17 deletions.
62 changes: 48 additions & 14 deletions src/main/java/me/truemb/rentit/listener/HotelAreaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ public void onPermissionForBreak(BlockBreakEvent e) {
e.setCancelled(canceled);
}

@EventHandler
public void onDoorBreak(BlockBreakEvent e) {
Player p = e.getPlayer();
Block b = e.getBlock();
Location loc = b.getLocation();

if((b.getBlockData() instanceof Door || b.getBlockData() instanceof TrapDoor || b.getBlockData() instanceof Gate) && this.instance.getDoorFileManager().isProtectedDoor(loc) && this.instance.getDoorFileManager().getTypeFromDoor(loc).equals(this.type)){
//DOOR LOCKED?

int hotelId = this.instance.getDoorFileManager().getIdFromDoor(loc);

RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, hotelId);

if (rentHandler == null)
return;

if (this.instance.getMethodes().hasPermissionForCommand(p, true, "hotel", "door.remove")) {

if(b.getState().getBlockData() instanceof Door) {
Door door = (Door) b.getState().getBlockData();
this.instance.getDoorFileManager().removeDoor(door, b.getLocation());
}else if(b.getState().getBlockData() instanceof TrapDoor || b.getState().getBlockData() instanceof Gate) {
this.instance.getDoorFileManager().removeDoor(b.getLocation());
}

p.sendMessage(this.instance.getMessage("hotelDoorRemoved"));
return;
}

e.setCancelled(true);
p.sendMessage(this.instance.getMessage("doorRemovePerm"));
}
}

@EventHandler
public void onPermissionForPlace(BlockPlaceEvent e) {

Expand Down Expand Up @@ -161,14 +195,14 @@ public void onInteraction(PlayerInteractEvent e) {
if((b.getBlockData() instanceof Door || b.getBlockData() instanceof TrapDoor || b.getBlockData() instanceof Gate) && this.instance.getDoorFileManager().isProtectedDoor(loc) && this.instance.getDoorFileManager().getTypeFromDoor(loc).equals(this.type)){
//DOOR LOCKED?

int shopId = this.instance.getDoorFileManager().getIdFromDoor(loc);
int hotelId = this.instance.getDoorFileManager().getIdFromDoor(loc);

RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, shopId);
RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, hotelId);

if (rentHandler == null)
return;

if(!this.instance.getAreaFileManager().isDoorStatusSet(this.type, shopId)) {
if(!this.instance.getAreaFileManager().isDoorStatusSet(this.type, hotelId)) {

if(!p.hasPermission(this.instance.manageFile().getString("Permissions.bypass.doors"))
&& this.instance.manageFile().isSet("Options.categorySettings.HotelCategory." + rentHandler.getCatID() + "." + CategorySettings.doorsClosedUntilBuy.toString())
Expand All @@ -188,12 +222,12 @@ public void onInteraction(PlayerInteractEvent e) {
}
}

if(this.instance.getAreaFileManager().isDoorClosed(this.type, shopId)) {
if(this.instance.getAreaFileManager().isDoorClosed(this.type, hotelId)) {
if(p.hasPermission(this.instance.manageFile().getString("Permissions.bypass.doors"))
|| ((!this.instance.manageFile().isSet("Options.categorySettings.HotelCategory." + rentHandler.getCatID() + "." + CategorySettings.ownerBypassLock.toString())
|| this.instance.manageFile().getBoolean("Options.categorySettings.HotelCategory." + rentHandler.getCatID() + "." + CategorySettings.ownerBypassLock.toString()))
&& (this.instance.getMethodes().hasPermission(this.type, shopId, uuid, this.instance.manageFile().getString("UserPermissions.hotel.Door"))
|| this.instance.getMethodes().hasPermission(this.type, shopId, uuid, this.instance.manageFile().getString("UserPermissions.hotel.Admin"))))) {
&& (this.instance.getMethodes().hasPermission(this.type, hotelId, uuid, this.instance.manageFile().getString("UserPermissions.hotel.Door"))
|| this.instance.getMethodes().hasPermission(this.type, hotelId, uuid, this.instance.manageFile().getString("UserPermissions.hotel.Admin"))))) {

e.setCancelled(false);
e.setUseInteractedBlock(Result.ALLOW);
Expand All @@ -214,9 +248,9 @@ public void onInteraction(PlayerInteractEvent e) {
}
}else if(b.getType() == Material.ENDER_CHEST) {

int shopId = this.instance.getAreaFileManager().getIdFromArea(this.type, loc);
int hotelId = this.instance.getAreaFileManager().getIdFromArea(this.type, loc);

RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, shopId);
RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, hotelId);

if (rentHandler == null)
return; //DOES SHOP EXISTS?
Expand All @@ -226,15 +260,15 @@ public void onInteraction(PlayerInteractEvent e) {
&& this.instance.manageFile().getBoolean("Options.categorySettings.HotelCategory." + rentHandler.getCatID() + "." + CategorySettings.useEnderchest.toString())) {

if(this.instance.getWorldGuard() != null) {
if(!this.instance.getMethodes().isMemberFromRegion(this.type, shopId, p.getWorld(), uuid)) {
if(!this.instance.getMethodes().isMemberFromRegion(this.type, hotelId, p.getWorld(), uuid)) {
e.setCancelled(true);
p.sendMessage(this.instance.getMessage("notShopOwner"));
return;
}
return;
}

if(rentHandler.getOwnerUUID() == null || !rentHandler.getOwnerUUID().equals(uuid) && !this.instance.getAreaFileManager().isMember(this.type, shopId, uuid)) {
if(rentHandler.getOwnerUUID() == null || !rentHandler.getOwnerUUID().equals(uuid) && !this.instance.getAreaFileManager().isMember(this.type, hotelId, uuid)) {
e.setCancelled(true);
p.sendMessage(this.instance.getMessage("notShopOwner"));
return;
Expand All @@ -244,9 +278,9 @@ public void onInteraction(PlayerInteractEvent e) {

}else if(b.getType().toString().contains("_BED")) {

int shopId = this.instance.getAreaFileManager().getIdFromArea(this.type, loc);
int hotelId = this.instance.getAreaFileManager().getIdFromArea(this.type, loc);

RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, shopId);
RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, hotelId);

if (rentHandler == null)
return; //DOES SHOP EXISTS?
Expand All @@ -256,15 +290,15 @@ public void onInteraction(PlayerInteractEvent e) {
&& this.instance.manageFile().getBoolean("Options.categorySettings.HotelCategory." + rentHandler.getCatID() + "." + CategorySettings.useBed.toString())) {

if(this.instance.getWorldGuard() != null) {
if(!this.instance.getMethodes().isMemberFromRegion(this.type, shopId, p.getWorld(), uuid)) {
if(!this.instance.getMethodes().isMemberFromRegion(this.type, hotelId, p.getWorld(), uuid)) {
e.setCancelled(true);
p.sendMessage(this.instance.getMessage("notShopOwner"));
return;
}
return;
}

if(rentHandler.getOwnerUUID() == null || !rentHandler.getOwnerUUID().equals(uuid) && !this.instance.getAreaFileManager().isMember(this.type, shopId, uuid)) {
if(rentHandler.getOwnerUUID() == null || !rentHandler.getOwnerUUID().equals(uuid) && !this.instance.getAreaFileManager().isMember(this.type, hotelId, uuid)) {
e.setCancelled(true);
p.sendMessage(this.instance.getMessage("notShopOwner"));
return;
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/me/truemb/rentit/listener/ShopAreaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ public void onPermissionForBreak(BlockBreakEvent e) {
e.setCancelled(canceled);
}

@EventHandler
public void onDoorBreak(BlockBreakEvent e) {
Player p = e.getPlayer();
Block b = e.getBlock();
Location loc = b.getLocation();

if((b.getBlockData() instanceof Door || b.getBlockData() instanceof TrapDoor || b.getBlockData() instanceof Gate) && this.instance.getDoorFileManager().isProtectedDoor(loc) && this.instance.getDoorFileManager().getTypeFromDoor(loc).equals(this.type)){
//DOOR LOCKED?

int shopId = this.instance.getDoorFileManager().getIdFromDoor(loc);

RentTypeHandler rentHandler = this.instance.getMethodes().getTypeHandler(this.type, shopId);

if (rentHandler == null)
return;

if (this.instance.getMethodes().hasPermissionForCommand(p, true, "shop", "door.remove")) {

if(b.getState().getBlockData() instanceof Door) {
Door door = (Door) b.getState().getBlockData();
this.instance.getDoorFileManager().removeDoor(door, b.getLocation());
}else if(b.getState().getBlockData() instanceof TrapDoor || b.getState().getBlockData() instanceof Gate) {
this.instance.getDoorFileManager().removeDoor(b.getLocation());
}

p.sendMessage(this.instance.getMessage("shopDoorRemoved"));
return;
}

e.setCancelled(true);
p.sendMessage(this.instance.getMessage("doorRemovePerm"));
}
}

@EventHandler
public void onPermissionForPlace(BlockPlaceEvent e) {

Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,14 @@ Messages:
noUserPermissionsSet: '&6You didnt give anyone Permissions for your &f&l%type%&6.'
doorsAlreadyLocked: '&6The Doors are already locked.'
doorsAlreadyUnlocked: '&6The Doors are already unlocked.'
doorRemovePerm: '&cSorry, you can''t break this door.'
pleaseReconnect: '&cSomething went wrong. Please reconnect.'
informAdmin: '&cSomething went wrong. Please inform an Admin.'
featureDisabled: '&cSorry, you are not allowed to do that.'
noPermsForCategory: '&cSorry, you are not allowed to rent this.'
autoPaymentDisabled: '&cSorry, you cant change auto Payment.'
doorCommandDisabled: '&cSorry, but this command doesnt work here.'
maxExtendedReached: '&cSorry, you cant extend the rent any farther.'
maxExtendedReached: '&cSorry, you can''t extend the rent any farther.'
#Shop Messages
adminshopPerm: '&cYou got no Permissions for this Admin Shop.'
adminshopNotSupported: '&cThis doesn''t work for Admin Shops.'
Expand Down Expand Up @@ -693,7 +694,7 @@ Messages:
shopMessageNoInfoOFF: '&6You set the Transactions Informations to &cdeactive&6.'
shopSellMessage: '&6The Player &f%player% &6has bought the Item &f%itemname% &6in your Shop.'
shopBuyMessage: '&6The Player &f%player% &6has sold the Item &f%itemname% &6to your Shop.'
shopDoorAdded: '&6The Door was added to the Shop: %alias%.'
shopDoorAdded: '&6The Door was added to the Shop: &f%alias%.'
shopDoorRemoved: '&6The Door was removed from a Shop.'
shopDoorNotFound: '&6The Door is not linked with a Shop.'
shopDoorClosed: '&6The Doors from this Shop were closed.'
Expand Down Expand Up @@ -834,7 +835,7 @@ Messages:
hotelRentRunningOut: '&4Your rent for your Hotelroom &f%alias% &4is running out. &8(%rentEnd%)'
notInHotel: '&cYou are in no Hotelroom.'
notHotelOwner: '&cYou got no Permission in this Hotelroom.'
hotelDoorAdded: '&6The Door was added to the Hotelroom: %alias%.'
hotelDoorAdded: '&6The Door was added to the Hotelroom: &f%alias%.'
hotelDoorRemoved: '&6The Door was removed from a Hotelroom.'
hotelDoorNotFound: '&6The Door is not linked with a Hotelroom.'
hotelDoorClosed: '&6The Doors from this Hotelroom were closed.'
Expand Down

0 comments on commit 21407f4

Please sign in to comment.