Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v0.82.1.11:

	- Move the BlockPhysics listener to it's own class so we don't register
it if it's not needed.
	- Allow protection of hopper minecarts from being right clicked.
  • Loading branch information...
commit ec218f448241c5c6cb3e92dc2a0949d65cad5cdf 1 parent 4d3f9a1
@ElgarL authored
View
5 src/ChangeLog.txt
@@ -1799,4 +1799,7 @@ v0.82.1.9:
- towny.wild.item_use.325
- Update the nations data in SQL when renaming towns.
v0.82.1.10:
- - Remove assitant override for town perms build/break. Thes should now only belong to the town Mayor. Assistant is just another rank.
+ - Remove assitant override for town perms build/break. Thes should now only belong to the town Mayor. Assistant is just another rank.
+v0.82.1.11:
+ - Move the BlockPhysics listener to it's own class so we don't register it if it's not needed.
+ - Allow protection of hopper minecarts from being right clicked.
View
7 src/com/palmergames/bukkit/towny/Towny.java
@@ -51,6 +51,7 @@
private final TownyPlayerListener playerListener = new TownyPlayerListener(this);
private final TownyBlockListener blockListener = new TownyBlockListener(this);
+ private final TownyBlockPhysicsListener physicsListener = new TownyBlockPhysicsListener(this);
private final TownyCustomListener customListener = new TownyCustomListener(this);
private final TownyEntityListener entityListener = new TownyEntityListener(this);
private final TownyWeatherListener weatherListener = new TownyWeatherListener(this);
@@ -343,6 +344,10 @@ private void registerEvents() {
pluginManager.registerEvents(townyWarCustomListener, this);
pluginManager.registerEvents(customListener, this);
pluginManager.registerEvents(worldListener, this);
+
+ // Only register a physics listener if we need to.
+ if (TownySettings.getRegenDelay() > 0)
+ pluginManager.registerEvents(physicsListener, this);
}
@@ -350,6 +355,8 @@ private void registerEvents() {
pluginManager.registerEvents(playerListener, this);
pluginManager.registerEvents(blockListener, this);
pluginManager.registerEvents(entityListener, this);
+
+
}
View
48 src/com/palmergames/bukkit/towny/listeners/TownyBlockListener.java
@@ -13,7 +13,6 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
-import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
@@ -31,7 +30,6 @@
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus;
-import com.palmergames.bukkit.towny.regen.NeedsPlaceholder;
import com.palmergames.bukkit.towny.regen.TownyRegenAPI;
import com.palmergames.bukkit.towny.regen.block.BlockLocation;
import com.palmergames.bukkit.towny.tasks.ProtectionRegenTask;
@@ -49,52 +47,6 @@ public TownyBlockListener(Towny instance) {
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockPhysics(BlockPhysicsEvent event) {
-
- if (plugin.isError()) {
- event.setCancelled(true);
- return;
- }
-
- /**
- * Exit if the regen timer is zero.
- */
- if (TownySettings.getRegenDelay() <= 0)
- return;
-
- //long start = System.currentTimeMillis();
-
- Block block = event.getBlock();
-
- if (block == null)
- return;
-
- BlockLocation blockLocation = new BlockLocation(block.getLocation());
-
- // if this is a placeholder remove it, as it's no longer needed.
- if (TownyRegenAPI.isPlaceholder(block)) {
- TownyRegenAPI.removePlaceholder(block);
- block.setTypeId(0, false);
- }
-
- if (TownyRegenAPI.hasProtectionRegenTask(blockLocation)) {
- //Cancel any physics events as we will be replacing this block
- event.setCancelled(true);
- } else {
- // Check the block below and cancel the event if that block is going to be replaced.
- Block blockBelow = block.getRelative(BlockFace.DOWN);
- blockLocation = new BlockLocation(blockBelow.getLocation());
-
- if (TownyRegenAPI.hasProtectionRegenTask(blockLocation) && (NeedsPlaceholder.contains(block.getType()))) {
- //System.out.print("Cancelling for Below on - " + block.getType().toString());
- event.setCancelled(true);
- }
- }
-
- //plugin.sendDebugMsg("onBlockPhysics took " + (System.currentTimeMillis() - start) + "ms ("+event.isCancelled() +")");
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (plugin.isError()) {
View
72 src/com/palmergames/bukkit/towny/listeners/TownyBlockPhysicsListener.java
@@ -0,0 +1,72 @@
+package com.palmergames.bukkit.towny.listeners;
+
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockPhysicsEvent;
+
+import com.palmergames.bukkit.towny.Towny;
+import com.palmergames.bukkit.towny.TownySettings;
+import com.palmergames.bukkit.towny.regen.NeedsPlaceholder;
+import com.palmergames.bukkit.towny.regen.TownyRegenAPI;
+import com.palmergames.bukkit.towny.regen.block.BlockLocation;
+
+
+public class TownyBlockPhysicsListener implements Listener {
+
+ private final Towny plugin;
+
+ public TownyBlockPhysicsListener(Towny instance) {
+
+ plugin = instance;
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockPhysics(BlockPhysicsEvent event) {
+
+ if (plugin.isError()) {
+ event.setCancelled(true);
+ return;
+ }
+
+ /**
+ * Exit if the regen timer is zero.
+ */
+ if (TownySettings.getRegenDelay() <= 0)
+ return;
+
+ //long start = System.currentTimeMillis();
+
+ Block block = event.getBlock();
+
+ if (block == null)
+ return;
+
+ BlockLocation blockLocation = new BlockLocation(block.getLocation());
+
+ // if this is a placeholder remove it, as it's no longer needed.
+ if (TownyRegenAPI.isPlaceholder(block)) {
+ TownyRegenAPI.removePlaceholder(block);
+ block.setTypeId(0, false);
+ }
+
+ if (TownyRegenAPI.hasProtectionRegenTask(blockLocation)) {
+ //Cancel any physics events as we will be replacing this block
+ event.setCancelled(true);
+ } else {
+ // Check the block below and cancel the event if that block is going to be replaced.
+ Block blockBelow = block.getRelative(BlockFace.DOWN);
+ blockLocation = new BlockLocation(blockBelow.getLocation());
+
+ if (TownyRegenAPI.hasProtectionRegenTask(blockLocation) && (NeedsPlaceholder.contains(block.getType()))) {
+ //System.out.print("Cancelling for Below on - " + block.getType().toString());
+ event.setCancelled(true);
+ }
+ }
+
+ //plugin.sendDebugMsg("onBlockPhysics took " + (System.currentTimeMillis() - start) + "ms ("+event.isCancelled() +")");
+ }
+
+}
View
18 src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java
@@ -23,8 +23,6 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
-import org.bukkit.entity.PoweredMinecart;
-import org.bukkit.entity.StorageMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -252,16 +250,24 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
case MINECART:
- if (event.getRightClicked() instanceof StorageMinecart) {
+ if (event.getRightClicked() instanceof org.bukkit.entity.minecart.StorageMinecart) {
blockID = 342;
- } else if (event.getRightClicked() instanceof PoweredMinecart) {
+ } else if (event.getRightClicked() instanceof org.bukkit.entity.minecart.RideableMinecart) {
- blockID = 321;
+ blockID = 328;
+
+ } else if (event.getRightClicked() instanceof org.bukkit.entity.minecart.PoweredMinecart) {
+
+ blockID = 343;
+
+ } else if (event.getRightClicked() instanceof org.bukkit.entity.minecart.HopperMinecart) {
+
+ blockID = 408;
} else {
-
+
blockID = 321;
}
Please sign in to comment.
Something went wrong with that request. Please try again.