Skip to content

Commit

Permalink
simplify nmshandler calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 16, 2019
1 parent 1ec39f3 commit 3e38726
Show file tree
Hide file tree
Showing 75 changed files with 352 additions and 508 deletions.
Expand Up @@ -131,8 +131,8 @@ public void onEntityBreeds(EntityBreedEvent event) {

// Prevent entities from continuing to breed with each other
if (cancelled && !wasCancelled) {
NMSHandler.getInstance().getEntityHelper().setBreeding((Animals) father.getLivingEntity(), false);
NMSHandler.getInstance().getEntityHelper().setBreeding((Animals) mother.getLivingEntity(), false);
NMSHandler.getEntityHelper().setBreeding((Animals) father.getLivingEntity(), false);
NMSHandler.getEntityHelper().setBreeding((Animals) mother.getLivingEntity(), false);
}
}
}
Expand Up @@ -138,7 +138,7 @@ public void onPlayerFishes(PlayerFishEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
Entity hookEntity = NMSHandler.getInstance().getEntityHelper().getFishHook(event);
Entity hookEntity = NMSHandler.getEntityHelper().getFishHook(event);
EntityTag.rememberEntity(hookEntity);
hook = new EntityTag(hookEntity);
state = new ElementTag(event.getState().toString());
Expand Down
Expand Up @@ -50,7 +50,7 @@ public PlayerKickedScriptEvent() {
public PlayerKickEvent event;

public boolean isFlying() {
return NMSHandler.getInstance().getPlayerHelper().getFlyKickCooldown(player.getPlayerEntity()) == 0;
return NMSHandler.getPlayerHelper().getFlyKickCooldown(player.getPlayerEntity()) == 0;
}

@Override
Expand Down Expand Up @@ -86,7 +86,7 @@ else if (lower.startsWith("reason:")) {
else if (lower.startsWith("fly_cooldown:")) {
DurationTag duration = DurationTag.valueOf(lower.substring("fly_cooldown:".length()));
if (duration != null) {
NMSHandler.getInstance().getPlayerHelper().setFlyKickCooldown(player.getPlayerEntity(), (int) duration.getTicks());
NMSHandler.getPlayerHelper().setFlyKickCooldown(player.getPlayerEntity(), (int) duration.getTicks());
cancelled = true;
return true;
}
Expand Down
Expand Up @@ -74,7 +74,7 @@ else if (name.equals("reason")) {
}
else if (name.equals("blocks")) {
ListTag blocks = new ListTag();
for (Location location : NMSHandler.getInstance().getBlockHelper().getBlocksList(event)) {
for (Location location : NMSHandler.getBlockHelper().getBlocksList(event)) {
blocks.addObject(new LocationTag(location));
}
return blocks;
Expand Down
90 changes: 65 additions & 25 deletions plugin/src/main/java/com/denizenscript/denizen/nms/NMSHandler.java
Expand Up @@ -74,55 +74,95 @@ public static JavaPlugin getJavaPlugin() {
return javaPlugin;
}

public boolean isCorrectMappingsCode() {
return true;
public AdvancementHelper advancementHelper;
public AnimationHelper animationHelper;
public BlockHelper blockHelper;
public ChunkHelper chunkHelper;
public CustomEntityHelper customEntityHelper;
public EntityHelper entityHelper;
public FishingHelper fishingHelper;
public ItemHelper itemHelper;
public SoundHelper soundHelper;
public PacketHelper packetHelper;
public ParticleHelper particleHelper;
public PlayerHelper playerHelper;
public WorldHelper worldHelper;

public static AdvancementHelper getAdvancementHelper() {
return getInstance().advancementHelper;
}

public abstract void disableAsyncCatcher();
public static AnimationHelper getAnimationHelper() {
return getInstance().animationHelper;
}

public abstract void undisableAsyncCatcher();
public static BlockHelper getBlockHelper() {
return getInstance().blockHelper;
}

public abstract Sidebar createSidebar(Player player);
public static ChunkHelper getChunkHelper() {
return getInstance().chunkHelper;
}

public abstract BlockLight createBlockLight(Location location, int lightLevel, long ticks);
public static CustomEntityHelper getCustomEntityHelper() {
return getInstance().customEntityHelper;
}

public abstract PlayerProfile fillPlayerProfile(PlayerProfile playerProfile);
public static EntityHelper getEntityHelper() {
return getInstance().entityHelper;
}

public abstract PlayerProfile getPlayerProfile(Player player);
public static FishingHelper getFishingHelper() {
return getInstance().fishingHelper;
}

public abstract ProfileEditor getProfileEditor();
public static ItemHelper getItemHelper() {
return getInstance().itemHelper;
}

public abstract BiomeNMS getBiomeNMS(Biome biome);
public static SoundHelper getSoundHelper() {
return getInstance().soundHelper;
}

public abstract Thread getMainThread();
public static PacketHelper getPacketHelper() {
return getInstance().packetHelper;
}

public abstract double[] getRecentTps();
public static ParticleHelper getParticleHelper() {
return getInstance().particleHelper;
}

public abstract AdvancementHelper getAdvancementHelper();
public static PlayerHelper getPlayerHelper() {
return getInstance().playerHelper;
}

public abstract AnimationHelper getAnimationHelper();
public static WorldHelper getWorldHelper() {
return getInstance().worldHelper;
}

public abstract BlockHelper getBlockHelper();
public boolean isCorrectMappingsCode() {
return true;
}

public abstract ChunkHelper getChunkHelper();
public abstract void disableAsyncCatcher();

public abstract CustomEntityHelper getCustomEntityHelper();
public abstract void undisableAsyncCatcher();

public abstract EntityHelper getEntityHelper();
public abstract Sidebar createSidebar(Player player);

public abstract FishingHelper getFishingHelper();
public abstract BlockLight createBlockLight(Location location, int lightLevel, long ticks);

public abstract ItemHelper getItemHelper();
public abstract PlayerProfile fillPlayerProfile(PlayerProfile playerProfile);

public abstract SoundHelper getSoundHelper();
public abstract PlayerProfile getPlayerProfile(Player player);

public abstract PacketHelper getPacketHelper();
public abstract ProfileEditor getProfileEditor();

public abstract ParticleHelper getParticleHelper();
public abstract BiomeNMS getBiomeNMS(Biome biome);

public abstract PlayerHelper getPlayerHelper();
public abstract Thread getMainThread();

public abstract WorldHelper getWorldHelper();
public abstract double[] getRecentTps();

public abstract void enablePacketInterception(PacketHandler packetHandler);

Expand Down
Expand Up @@ -23,9 +23,9 @@ public ModernBlockData(Material material) {
}

public ModernBlockData(Block block) {
NMSHandler.getInstance().getChunkHelper().changeChunkServerThread(block.getWorld());
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
this.data = block.getBlockData();
NMSHandler.getInstance().getChunkHelper().restoreServerThread(block.getWorld());
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
}

public ModernBlockData(BlockState block) {
Expand All @@ -41,7 +41,7 @@ public Material getMaterial() {
}

public BlockState getBlockState() {
BlockState state = NMSHandler.getInstance().getBlockHelper().generateBlockState(getMaterial());
BlockState state = NMSHandler.getBlockHelper().generateBlockState(getMaterial());
state.setBlockData(data);
return state;
}
Expand Down Expand Up @@ -72,10 +72,10 @@ else if (data instanceof Dispenser) {
else {
return false;
}
NMSHandler.getInstance().getChunkHelper().changeChunkServerThread(block.getWorld());
NMSHandler.getChunkHelper().changeChunkServerThread(block.getWorld());
block.setBlockData(data, true);
block.getState().update(true, true);
NMSHandler.getInstance().getChunkHelper().restoreServerThread(block.getWorld());
NMSHandler.getChunkHelper().restoreServerThread(block.getWorld());
return true;
}

Expand Down
Expand Up @@ -497,6 +497,6 @@ else if (337.5 <= yaw && yaw < 360.0) {
public abstract void setCarryingChest(Entity horse, boolean carrying);

public BlockData getBlockDataFor(FallingBlock entity) {
return NMSHandler.getInstance().getBlockHelper().getBlockData(entity.getMaterial(), (byte) 0);
return NMSHandler.getBlockHelper().getBlockData(entity.getMaterial(), (byte) 0);
}
}
Expand Up @@ -46,7 +46,7 @@ public static Location getWalkableLocationNear(Location location, int range) {
}

public static boolean isWalkable(Location location) {
BlockHelper blockHelper = NMSHandler.getInstance().getBlockHelper();
BlockHelper blockHelper = NMSHandler.getBlockHelper();
return !blockHelper.isSafeBlock(location.clone().subtract(0, 1, 0).getBlock().getType())
&& blockHelper.isSafeBlock(location.getBlock().getType())
&& blockHelper.isSafeBlock(location.clone().add(0, 1, 0).getBlock().getType());
Expand Down
Expand Up @@ -178,7 +178,7 @@ private void cast() {
v = v + (CoreUtilities.getRandom().nextDouble() - .8) / 2;
victor = victor.multiply(v / 20.0);

fishHook = NMSHandler.getInstance().getFishingHelper().spawnHook(from, (Player) npc.getEntity());
fishHook = NMSHandler.getFishingHelper().spawnHook(from, (Player) npc.getEntity());
fishHook.setShooter((ProjectileSource) npc.getEntity());
fishHook.setVelocity(victor);

Expand Down Expand Up @@ -213,7 +213,7 @@ private void reel() {
catch (Exception e) {
}
Location location = fishHook.getLocation();
ItemStack result = NMSHandler.getInstance().getFishingHelper().getResult(fishHook, catchType);
ItemStack result = NMSHandler.getFishingHelper().getResult(fishHook, catchType);
if (result != null) {
fish = location.getWorld().dropItem(location, result);
Location npcLocation = npc.getEntity().getLocation();
Expand Down
Expand Up @@ -180,7 +180,7 @@ public ChunkSnapshot getSnapshot() {
}

public int[] getHeightMap() {
return NMSHandler.getInstance().getChunkHelper().getHeightMap(getChunk());
return NMSHandler.getChunkHelper().getHeightMap(getChunk());
}

String prefix = "Chunk";
Expand Down Expand Up @@ -671,7 +671,7 @@ public void run() {
// None
// -->
if (mechanism.matches("refresh_chunk_sections")) {
NMSHandler.getInstance().getChunkHelper().refreshChunkSections(getChunk());
NMSHandler.getChunkHelper().refreshChunkSections(getChunk());
}

CoreUtilities.autoPropertyMechanism(this, mechanism);
Expand Down
Expand Up @@ -674,7 +674,7 @@ public ListTag getSpawnableBlocks(List<MaterialTag> mats) {
ListTag list = new ListTag();
int index = 0;

BlockHelper blockHelper = NMSHandler.getInstance().getBlockHelper();
BlockHelper blockHelper = NMSHandler.getBlockHelper();
for (LocationPair pair : pairs) {

LocationTag loc_1 = pair.low;
Expand Down

0 comments on commit 3e38726

Please sign in to comment.