11package net .tfminecraft .dowsing .managers ;
22
33import java .util .ArrayList ;
4+ import java .util .Collection ;
45import java .util .HashMap ;
56import java .util .List ;
67import java .util .Map ;
@@ -128,9 +129,9 @@ public static Integer getNodeCapacity(Guild g) {
128129 if (added > Cache .maxMemberCapacity ) {
129130 added = Cache .maxMemberCapacity ;
130131 }
131- capacity = capacity +added + getExtraCapacity ( g ) ;
132+ capacity = capacity +added ;
132133 }
133- return capacity ;
134+ return capacity + getExtraCapacity ( g ) ;
134135 }
135136 public Node getByLocation (Location loc ) {
136137 for (Node n : nodes ) {
@@ -139,7 +140,7 @@ public Node getByLocation(Location loc) {
139140 return null ;
140141 }
141142 public String getClickedFurniture (Block b ) {
142- List <Entity > nearbyEntities = ( List < Entity >) b .getWorld ().getNearbyEntities (b .getLocation (), 0.2 , 0.2 , 0.2 );
143+ Collection <Entity > nearbyEntities = b .getWorld ().getNearbyEntities (b .getLocation (), 0.2 , 0.2 , 0.2 );
143144 for (Entity a : b .getWorld ().getEntities ()){
144145 if (nearbyEntities .contains (a )){
145146 CustomFurniture f = CustomFurniture .byAlreadySpawned (a );
@@ -230,12 +231,14 @@ public void validate() {
230231 Node n = nodes .get (i );
231232 if (!n .getLoc ().getBlock ().getType ().equals (Material .BARRIER )) {
232233 n .breakNode ();
233- nodes .remove (i );
234+ nodes .remove (i -- );
234235 }
235236 }
236237 }
237238 public void confirmClick (Player p , Node n , ConfirmType t ) {
238239 if (t != ConfirmType .DEACTIVATE && blockPendingRefund (p , n )) return ;
240+ if (t != ConfirmType .DEACTIVATE && blockActiveChange (p , n ,
241+ t == ConfirmType .DELETE_NODE ? "delete node" : "change type" )) return ;
239242 if (t .equals (ConfirmType .DEACTIVATE )) {
240243 boolean wasActive = n .getIsActive ();
241244 n .deActivate ();
@@ -260,12 +263,28 @@ public void confirmClick(Player p, Node n, ConfirmType t) {
260263 inv .nodeView (p , n );
261264 currentNode .put (p , n );
262265 }
266+ confirm .remove (p );
263267 }
264268 private boolean blockPendingRefund (Player p , Node n ) {
265269 if (!n .hasPendingRefund ()) return false ;
266270 p .sendMessage ("§cRestore the barrel and hopper, then click Retry Refund before changing this node." );
267271 return true ;
268272 }
273+ private boolean canManageNode (Player p , Node n ) {
274+ if (p .hasPermission ("dowsing.admin" )) return true ;
275+ Guild memberGuild = FactionManager .getGuildByMember (p .getName ());
276+ Guild owner = n .getGuild ();
277+ if (memberGuild != null && owner != null && owner .getId ().equalsIgnoreCase (memberGuild .getId ())) return true ;
278+ p .sendMessage ("§cCannot change another guild's node" );
279+ p .playSound (p .getLocation (), Sound .ENTITY_VILLAGER_NO , 1f , 1f );
280+ return false ;
281+ }
282+ private boolean blockActiveChange (Player p , Node n , String action ) {
283+ if (!n .getIsActive ()) return false ;
284+ p .sendMessage ("§cCannot " +action +" while node is active" );
285+ p .playSound (p .getLocation (), Sound .ENTITY_VILLAGER_NO , 1f , 1f );
286+ return true ;
287+ }
269288 @ EventHandler (ignoreCancelled = true )
270289 public void placeVanillaNode (BlockPlaceEvent e ) {
271290 NodeBlock b = BlockLoader .getByBlock (e .getBlock ().getType ());
@@ -407,11 +426,7 @@ public void invenClick(InventoryClickEvent e) {
407426 return ;
408427 }
409428 Guild g = FactionManager .getGuildByMember (p .getName ());
410- if (!p .hasPermission ("dowsing.admin" ) && (g == null || n .getGuild () == null || !n .getGuild ().getId ().equalsIgnoreCase (g .getId ()))) {
411- p .sendMessage ("§cCannot change another guild's node" );
412- p .playSound (p .getLocation (), Sound .ENTITY_VILLAGER_NO , 1f , 1f );
413- return ;
414- }
429+ if (!canManageNode (p , n )) return ;
415430 if (e .getSlot () != 17 && blockPendingRefund (p , n )) return ;
416431 if (e .getSlot () == 8 ) {
417432 if (n .getIsActive ()) {
@@ -517,6 +532,8 @@ public void invenClick(InventoryClickEvent e) {
517532 return ;
518533 }
519534 NodeSlot slot = currentSlot .get (p );
535+ if (!canManageNode (p , n )) return ;
536+ if (blockActiveChange (p , n , "change production methods" )) return ;
520537 ItemStack i = e .getCurrentItem ();
521538 if (i == null ) return ;
522539 ProductionMethod pm = PMLoader .getByItemName (i .getItemMeta ().getDisplayName ());
@@ -553,6 +570,8 @@ public void invenClick(InventoryClickEvent e) {
553570 p .playSound (p .getLocation (), Sound .BLOCK_NOTE_BLOCK_BIT , 1f , 1f );
554571 return ;
555572 }
573+ if (!canManageNode (p , n )) return ;
574+ if (blockActiveChange (p , n , "change type" )) return ;
556575 ItemStack i = e .getCurrentItem ();
557576 if (i == null ) return ;
558577 NodeType t = TypeLoader .getByItemName (i .getItemMeta ().getDisplayName ());
@@ -582,10 +601,10 @@ public void invenClick(InventoryClickEvent e) {
582601 return ;
583602 }
584603 if (!confirm .containsKey (p )) return ;
604+ if (e .getSlot () == 11 && !canManageNode (p , n )) return ;
585605 p .playSound (p .getLocation (), Sound .BLOCK_NOTE_BLOCK_BIT , 1f , 1f );
586606 if (e .getSlot () == 11 ) {
587607 confirmClick (p , n , confirm .get (p ));
588- confirm .remove (p );
589608 } else if (e .getSlot () == 15 ) {
590609 inv .nodeView (p , n );
591610 currentNode .put (p , n );
0 commit comments