This commit is contained in:
Ghost_chu committed 2018-07-30 18:39:07 +08:00
1 parent 96073a1ad4
commit c611e33172
4 files changed
+798 -1137

No files matched your search

@@ -1,79 +1,82 @@
package org.maxgamer.quickshop.Listeners;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Shop.Shop;
import org.maxgamer.quickshop.Shop.ShopChunk;
public class WorldListener implements Listener {
QuickShop plugin;
public WorldListener(QuickShop plugin) {
this.plugin = plugin;
}
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
/* *************************************
* This listener fixes any broken world references. Such as hashmap
* lookups will fail, because the World reference is different, but the
* world value is the same. ************************************
*/
World world = e.getWorld();
// New world data
HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<ShopChunk, HashMap<Location, Shop>>(1);
// Old world data
HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
// Nothing in the old world, therefore we don't care. No locations to
// update.
if (oldInWorld == null)
return;
for (Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) {
HashMap<Location, Shop> inChunk = new HashMap<Location, Shop>(1);
// Put the new chunk were the old chunk was
inWorld.put(oldInChunk.getKey(), inChunk);
for (Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {
Shop shop = entry.getValue();
shop.getLocation().setWorld(world);
inChunk.put(shop.getLocation(), shop);
}
}
// Done - Now we can store the new world dataz!
plugin.getShopManager().getShops().put(world.getName(), inWorld);
// This is a workaround, because I don't get parsed chunk events when a
// world first loads....
// So manually tell all of these shops they're loaded.
for (Chunk chunk : world.getLoadedChunks()) {
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
if (inChunk == null)
continue;
for (Shop shop : inChunk.values()) {
shop.onLoad();
}
}
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent e) {
// This is a workaround, because I don't get parsed chunk events when a
// world unloads, I think...
// So manually tell all of these shops they're unloaded.
for (Chunk chunk : e.getWorld().getLoadedChunks()) {
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
if (inChunk == null)
continue;
for (Shop shop : inChunk.values()) {
shop.onUnload();
}
}
}
package org.maxgamer.quickshop.Listeners;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.Shop.Shop;
import org.maxgamer.quickshop.Shop.ShopChunk;
public class WorldListener implements Listener {
QuickShop plugin;
public WorldListener(QuickShop plugin) {
this.plugin = plugin;
}
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
Bukkit.getServer().broadcastMessage("´¥·¢WorldLoadEvent");
/* *************************************
* This listener fixes any broken world references. Such as hashmap
* lookups will fail, because the World reference is different, but the
* world value is the same. ************************************
*/
World world = e.getWorld();
// New world data
HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<ShopChunk, HashMap<Location, Shop>>(1);
// Old world data
HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
// Nothing in the old world, therefore we don't care. No locations to
// update.
if (oldInWorld == null)
return;
for (Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) {
HashMap<Location, Shop> inChunk = new HashMap<Location, Shop>(1);
// Put the new chunk were the old chunk was
inWorld.put(oldInChunk.getKey(), inChunk);
for (Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {
Shop shop = entry.getValue();
shop.getLocation().setWorld(world);
inChunk.put(shop.getLocation(), shop);
}
}
// Done - Now we can store the new world dataz!
plugin.getShopManager().getShops().put(world.getName(), inWorld);
// This is a workaround, because I don't get parsed chunk events when a
// world first loads....
// So manually tell all of these shops they're loaded.
for (Chunk chunk : world.getLoadedChunks()) {
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
if (inChunk == null)
continue;
for (Shop shop : inChunk.values()) {
shop.onLoad();
}
}
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent e) {
Bukkit.getServer().broadcastMessage("´¥·¢WorldUnloadEvent");
// This is a workaround, because I don't get parsed chunk events when a
// world unloads, I think...
// So manually tell all of these shops they're unloaded.
for (Chunk chunk : e.getWorld().getLoadedChunks()) {
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
if (inChunk == null)
continue;
for (Shop shop : inChunk.values()) {
shop.onUnload();
}
}
}
}
File diff suppressed because it is too large. Load diff
@@ -285,6 +285,7 @@ public class Util {
item.addEnchantment(ench, level);
}
}
Bukkit.getServer().broadcastMessage("´¥·¢makeItem");
return item;
}
@@ -429,353 +430,8 @@ public class Util {
* @return A string with the name of the item.
*/
private static String getDataName(Material mat, short damage) {
int id = mat.getId();
switch (id) {
case 35:
switch ((int) damage) {
case 0:
return "WHITE_WOOL";
case 1:
return "ORANGE_WOOL";
case 2:
return "MAGENTA_WOOL";
case 3:
return "LIGHT_BLUE_WOOL";
case 4:
return "YELLOW_WOOL";
case 5:
return "LIME_WOOL";
case 6:
return "PINK_WOOL";
case 7:
return "GRAY_WOOL";
case 8:
return "LIGHT_GRAY_WOOL";
case 9:
return "CYAN_WOOL";
case 10:
return "PURPLE_WOOL";
case 11:
return "BLUE_WOOL";
case 12:
return "BROWN_WOOL";
case 13:
return "GREEN_WOOL";
case 14:
return "RED_WOOL";
case 15:
return "BLACK_WOOL";
}
return mat.toString();
case 351:
switch ((int) damage) {
case 0:
return "INK_SAC";
case 1:
return "ROSE_RED";
case 2:
return "CACTUS_GREEN";
case 3:
return "COCOA_BEANS";
case 4:
return "LAPIS_LAZULI";
case 5:
return "PURPLE_DYE";
case 6:
return "CYAN_DYE";
case 7:
return "LIGHT_GRAY_DYE";
case 8:
return "GRAY_DYE";
case 9:
return "PINK_DYE";
case 10:
return "LIME_DYE";
case 11:
return "DANDELION_YELLOW";
case 12:
return "LIGHT_BLUE_DYE";
case 13:
return "MAGENTA_DYE";
case 14:
return "ORANGE_DYE";
case 15:
return "BONE_MEAL";
}
return mat.toString();
case 98:
switch ((int) damage) {
case 0:
return "STONE_BRICKS";
case 1:
return "MOSSY_STONE_BRICKS";
case 2:
return "CRACKED_STONE_BRICKS";
case 3:
return "CHISELED_STONE_BRICKS";
}
return mat.toString();
case 373:
// Special case,.. Why?
if (damage == 0)
return "WATER_BOTTLE";
Potion pot;
try {
pot = Potion.fromDamage(damage);
} catch (Exception e) {
return "CUSTOM_POTION";
}
String prefix = "";
String suffix = "";
if (pot.getLevel() > 0)
suffix += "_" + pot.getLevel();
if (pot.hasExtendedDuration())
prefix += "EXTENDED_";
if (pot.isSplash())
prefix += "SPLASH_";
if (pot.getEffects().isEmpty()) {
switch ((int) pot.getNameId()) {
case 0:
return prefix + "MUNDANE_POTION" + suffix;
case 7:
return prefix + "CLEAR_POTION" + suffix;
case 11:
return prefix + "DIFFUSE_POTION" + suffix;
case 13:
return prefix + "ARTLESS_POTION" + suffix;
case 15:
return prefix + "THIN_POTION" + suffix;
case 16:
return prefix + "AWKWARD_POTION" + suffix;
case 32:
return prefix + "THICK_POTION" + suffix;
}
} else {
String effects = "";
for (PotionEffect effect : pot.getEffects()) {
effects += effect.toString().split(":")[0];
}
return prefix + effects + suffix;
}
return mat.toString();
case 6:
switch ((int) damage) {
case 0:
return "OAK_SAPLING";
case 1:
return "PINE_SAPLING";
case 2:
return "BIRCH_SAPLING";
case 3:
return "JUNGLE_TREE_SAPLING";
}
return mat.toString();
case 5:
switch ((int) damage) {
case 0:
return "OAK_PLANKS";
case 1:
return "PINE_PLANKS";
case 2:
return "BIRCH_PLANKS";
case 3:
return "JUNGLE_PLANKS";
}
return mat.toString();
case 17:
switch (damage) {
case 0:
return "OAK_LOG";
case 1:
return "PINE_LOG";
case 2:
return "BIRCH_LOG";
case 3:
return "JUNGLE_LOG";
}
return mat.toString();
case 18:
damage = (short) (damage % 4);
switch (damage) {
case 0:
return "OAK_LEAVES";
case 1:
return "PINE_LEAVES";
case 2:
return "BIRCH_LEAVES";
case 3:
return "JUNGLE_LEAVES";
}
case 263:
switch (damage) {
case 0:
return "COAL";
case 1:
return "CHARCOAL";
}
return mat.toString();
case 24:
switch ((int) damage) {
case 0:
return "SANDSTONE";
case 1:
return "CHISELED_SANDSTONE";
case 2:
return "SMOOTH_SANDSTONE";
}
return mat.toString();
case 31:
switch ((int) damage) {
case 0:
return "DEAD_SHRUB";
case 1:
return "TALL_GRASS";
case 2:
return "FERN";
}
return mat.toString();
case 44:
switch ((int) damage) {
case 0:
return "STONE_SLAB";
case 1:
return "SANDSTONE_SLAB";
case 2:
return "WOODEN_SLAB";
case 3:
return "COBBLESTONE_SLAB";
case 4:
return "BRICK_SLAB";
case 5:
return "STONE_BRICK_SLAB";
}
return mat.toString();
case 383:
switch ((int) damage) {
case 50:
return "CREEPER_EGG";
case 51:
return "SKELETON_EGG";
case 52:
return "SPIDER_EGG";
case 53:
return "GIANT_EGG";
case 54:
return "ZOMBIE_EGG";
case 55:
return "SLIME_EGG";
case 56:
return "GHAST_EGG";
case 57:
return "ZOMBIE_PIGMAN_EGG";
case 58:
return "ENDERMAN_EGG";
case 59:
return "CAVE_SPIDER_EGG";
case 60:
return "SILVERFISH_EGG";
case 61:
return "BLAZE_EGG";
case 62:
return "MAGMA_CUBE_EGG";
case 63:
return "ENDER_DRAGON_EGG";
case 90:
return "PIG_EGG";
case 91:
return "SHEEP_EGG";
case 92:
return "COW_EGG";
case 93:
return "CHICKEN_EGG";
case 94:
return "SQUID_EGG";
case 95:
return "WOLF_EGG";
case 96:
return "MOOSHROOM_EGG";
case 97:
return "SNOW_GOLEM_EGG";
case 98:
return "OCELOT_EGG";
case 99:
return "IRON_GOLEM_EGG";
case 120:
return "VILLAGER_EGG";
case 200:
return "ENDER_CRYSTAL_EGG";
case 14:
return "PRIMED_TNT_EGG";
case 66:
return "WITCH_EGG";
case 65:
return "BAT_EGG";
}
return mat.toString();
case 397:
switch ((int) damage) {
case 0:
return "SKELETON_SKULL";
case 1:
return "WITHER_SKULL";
case 2:
return "ZOMBIE_HEAD";
case 3:
return "PLAYER_HEAD";
case 4:
return "CREEPER_HEAD";
}
break;
case 76:
return "REDSTONE_TORCH";
case 115:
return "NETHER_WART";
case 30:
return "COBWEB";
case 102:
return "GLASS_PANE";
case 101:
return "IRON_BARS";
case 58:
return "CRAFTING_TABLE";
case 123:
return "REDSTONE_LAMP";
case 392:
return "POTATO";
case 289:
return "GUNPOWDER";
case 391:
return "CARROT";
case 322:
switch ((int) damage) {
case 0:
return "GOLDEN_APPLE";
case 1:
return "ENCHANTED_GOLDEN_APPLE";
}
break;
case 390:
return "FLOWER_POT";
case 145:
switch ((int) damage) {
case 0:
return "ANVIL";
case 1:
return "SLIGHTLY_DAMAGED_ANVIL";
case 2:
return "VERY_DAMAGED:ANVIL";
}
break;
case 384:
return "BOTTLE_O'_ENCHANTING";
case 402:
return "FIREWORK_STAR";
case 385:
return "FIREWORK_CHARGE";
}
if (damage == 0 || isTool(mat))
return mat.toString();
return mat.toString() + ":" + damage;
return mat.name();
//Not need in 1.13
}
/**