Skip to content

Commit

Permalink
Fixed Rumble destroying Paintings and Itemframes with its shockwave a…
Browse files Browse the repository at this point in the history
…nd set default config language
  • Loading branch information
Taiterio authored and Taiterio committed Jul 22, 2015
1 parent 36014f6 commit 09d02f1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ tmp/
local.properties
.settings/
.loadpath
.jardesc

# Eclipse Core
.project
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/think/rpgitems/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
Expand Down Expand Up @@ -73,6 +75,15 @@ public class Events implements Listener {
public static TObjectIntHashMap<String> recipeWindows = new TObjectIntHashMap<String>();
public static HashMap<String, Set<Integer>> drops = new HashMap<String, Set<Integer>>();
public static boolean useLocaleInv = false;

@EventHandler
public void onHangingBreak(HangingBreakEvent e) {
if(e.getCause().equals(RemoveCause.EXPLOSION))
if(e.getEntity().hasMetadata("Rumble")) {
e.getEntity().removeMetadata("Rumble", Plugin.plugin); //Allow the entity to be broken again
e.setCancelled(true);
}
}

@SuppressWarnings("deprecation")
@EventHandler(ignoreCancelled = true)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/think/rpgitems/data/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ private Locale(Plugin plugin) {
plugin.getConfig().set("localeDownload", true);
plugin.saveConfig();
}
if (!plugin.getConfig().contains("language")) {
plugin.getConfig().set("language", "en_GB");
plugin.saveConfig();
}
}

private final static String localeUpdateURL = "http://198.199.127.128/rpgitems/index.php?page=localeget&lastupdate=";
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/think/rpgitems/power/PowerRumble.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@

import java.util.Random;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -101,12 +106,17 @@ public void run() {
}
}
if (hit) {
location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), power, false, false);
near = getNearbyEntities(location, 2.5);
for (Entity e : near) {
if (e != player)
if (e != player) {
if(e instanceof ItemFrame || e instanceof Painting) {
e.setMetadata("Rumble", new FixedMetadataValue(Plugin.plugin, null)); //Add metadata to protect hanging entities from the explosion
continue;
}
e.setVelocity(new Vector(random.nextGaussian() / 4d, 1d + random.nextDouble() * (double) power, random.nextGaussian() / 4d));
}
}
location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), power, false, false); //Trigger the explosion after all hanging entities have been protected
cancel();
return;
}
Expand Down

0 comments on commit 09d02f1

Please sign in to comment.