Skip to content

Commit

Permalink
mix of automated and manual cleanups and java modernizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 5, 2021
1 parent 9c2cb2f commit 7746cf8
Show file tree
Hide file tree
Showing 160 changed files with 1,371 additions and 2,203 deletions.
Expand Up @@ -111,14 +111,13 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("entity")) {
return entity.getDenizenObject();
}
else if (name.equals("damager")) {
return hitBy.getDenizenObject();
}
else if (name.equals("acceleration")) {
return new LocationTag(event.getAcceleration());
switch (name) {
case "entity":
return entity.getDenizenObject();
case "damager":
return hitBy.getDenizenObject();
case "acceleration":
return new LocationTag(event.getAcceleration());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -98,17 +98,15 @@ public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {

@Override
public ObjectTag getContext(String name) {
if (name.equals("entity")) {
return entity.getDenizenObject();
}
else if (name.equals("crossbow")) {
return new ItemTag(event.getCrossbow());
}
else if (name.equals("hand")) {
return new ElementTag(event.getHand().name());
}
else if (name.equals("consumes")) {
return new ElementTag(event.shouldConsumeItem());
switch (name) {
case "entity":
return entity.getDenizenObject();
case "crossbow":
return new ItemTag(event.getCrossbow());
case "hand":
return new ElementTag(event.getHand().name());
case "consumes":
return new ElementTag(event.shouldConsumeItem());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -90,17 +90,15 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return new LocationTag(event.getBlock().getLocation());
}
else if (name.equals("effect")) {
return new ElementTag(ItemPotion.stringifyEffect(event.getEffect()));
}
else if (name.equals("effect_type")) {
return new ElementTag(event.getEffect().getType().getName());
}
else if (name.equals("is_primary")) {
return new ElementTag(event.isPrimary());
switch (name) {
case "location":
return new LocationTag(event.getBlock().getLocation());
case "effect":
return new ElementTag(ItemPotion.stringifyEffect(event.getEffect()));
case "effect_type":
return new ElementTag(event.getEffect().getType().getName());
case "is_primary":
return new ElementTag(event.isPrimary());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -78,17 +78,17 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("entity")) {
FakeEntity fakeEntity = FakeEntity.getFakeEntityFor(event.getPlayer().getUniqueId(), event.getEntityId());
if (fakeEntity != null) {
return fakeEntity.entity;
}
}
else if (name.equals("hand")) {
return new ElementTag(event.getHand().name());
}
else if (name.equals("click_type")) {
return new ElementTag(event.isAttack() ? "left" : "right");
switch (name) {
case "entity":
FakeEntity fakeEntity = FakeEntity.getFakeEntityFor(event.getPlayer().getUniqueId(), event.getEntityId());
if (fakeEntity != null) {
return fakeEntity.entity;
}
break;
case "hand":
return new ElementTag(event.getHand().name());
case "click_type":
return new ElementTag(event.isAttack() ? "left" : "right");
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -117,14 +117,13 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("new_item")) {
return newItem;
}
else if (name.equals("old_item")) {
return oldItem;
}
else if (name.equals("slot")) {
return new ElementTag(namesBySlot.get(slot));
switch (name) {
case "new_item":
return newItem;
case "old_item":
return oldItem;
case "slot":
return new ElementTag(namesBySlot.get(slot));
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -49,14 +49,13 @@ else if (lower.startsWith("exclude_players:")) {

@Override
public ObjectTag getContext(String name) {
if (name.equals("protocol_version")) {
return new ElementTag(((PaperServerListPingEvent) event).getProtocolVersion());
}
else if (name.equals("version_name")) {
return new ElementTag(((PaperServerListPingEvent) event).getVersion());
}
else if (name.equals("client_protocol_version")) {
return new ElementTag(((PaperServerListPingEvent) event).getClient().getProtocolVersion());
switch (name) {
case "protocol_version":
return new ElementTag(((PaperServerListPingEvent) event).getProtocolVersion());
case "version_name":
return new ElementTag(((PaperServerListPingEvent) event).getVersion());
case "client_protocol_version":
return new ElementTag(((PaperServerListPingEvent) event).getClient().getProtocolVersion());
}
return super.getContext(name);
}
Expand Down
87 changes: 33 additions & 54 deletions plugin/src/main/java/com/denizenscript/denizen/Denizen.java
Expand Up @@ -396,46 +396,40 @@ else if (javaVersion.startsWith("9") || javaVersion.startsWith("1.9") || javaVer
Debug.echoError(ex);
}
// Run everything else on the first server tick
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
try {
exCommand.processTagList();
// Process script files (events, etc).
DenizenCore.postLoadScripts();
// Synchronize any script commands added while loading scripts.
CommandScriptHelper.syncDenizenCommands();
// Reload notables from notables.yml into memory
notableManager.reloadNotables();
Debug.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
// Fire the 'on Server Start' world event
ServerStartScriptEvent.instance.fire();
worldScriptHelper.serverStartEvent();
if (Settings.allowStupidx()) {
Debug.echoError("Don't screw with bad config values.");
Bukkit.shutdown();
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.this, new Runnable() {
@Override
public void run() {
Debug.outputThisTick = 0;
Debug.errorDuplicatePrevention = false;
DenizenCore.tick(50); // Sadly, minecraft has no delta timing, so a tick is always 50ms.
}
}, 1, 1);
InventoryTag.setupInventoryTracker();
if (!MapTagBasedFlagTracker.skipAllCleanings && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_16)) {
for (World world : Bukkit.getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) {
new DataPersistenceFlagTracker(chunk).doTotalClean();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
try {
exCommand.processTagList();
// Process script files (events, etc).
DenizenCore.postLoadScripts();
// Synchronize any script commands added while loading scripts.
CommandScriptHelper.syncDenizenCommands();
// Reload notables from notables.yml into memory
notableManager.reloadNotables();
Debug.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
// Fire the 'on Server Start' world event
ServerStartScriptEvent.instance.fire();
worldScriptHelper.serverStartEvent();
if (Settings.allowStupidx()) {
Debug.echoError("Don't screw with bad config values.");
Bukkit.shutdown();
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.this, () -> {
Debug.outputThisTick = 0;
Debug.errorDuplicatePrevention = false;
DenizenCore.tick(50); // Sadly, minecraft has no delta timing, so a tick is always 50ms.
}, 1, 1);
InventoryTag.setupInventoryTracker();
if (!MapTagBasedFlagTracker.skipAllCleanings && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_16)) {
for (World world : Bukkit.getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) {
new DataPersistenceFlagTracker(chunk).doTotalClean();
}
}
Debug.log("Denizen fully loaded at: " + TimeTag.now().format());
}
catch (Exception e) {
Debug.echoError(e);
}
Debug.log("Denizen fully loaded at: " + TimeTag.now().format());
}
catch (Exception e) {
Debug.echoError(e);
}
}, 1);
new BukkitRunnable() {
Expand Down Expand Up @@ -484,35 +478,20 @@ public void onDisable() {
if (!startedSuccessful) {
return;
}

if (hasDisabled) {
return;
}
hasDisabled = true;

ServerStopScriptEvent.instance.fire();

// Disable the log interceptor... otherwise bad things on /reload
/*if (logInterceptor != null) {
logInterceptor.standardOutput();
}*/

// Save notables
notableManager.saveNotables();

// Save scoreboards
ScoreboardHelper._saveScoreboards();

// Save offline player inventories
InventoryScriptHelper._savePlayerInventories();

//Disable core members
getCommandRegistry().disableCoreMembers();

triggerRegistry.disableCoreMembers();
DenizenCore.logInterceptor.standardOutput();
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled.");
Bukkit.getServer().getScheduler().cancelTasks(this);
HandlerList.unregisterAll(this);

saveSaves(false);
worldFlags.shutdown();
}
Expand Down
Expand Up @@ -957,35 +957,27 @@ public boolean tryEntity(EntityTag entity, String comparedto) {
Entity bEntity = entity.getBukkitEntity();
comparedto = CoreUtilities.toLowerCase(comparedto);
if (specialEntityMatchables.contains(comparedto)) {
if (comparedto.equals("entity")) {
return true;
}
else if (comparedto.equals("npc")) {
return entity.isCitizensNPC();
}
else if (comparedto.equals("player")) {
return entity.isPlayer();
}
else if (comparedto.equals("vehicle")) {
return bEntity instanceof Vehicle;
}
else if (comparedto.equals("fish")) {
return bEntity instanceof Fish;
}
else if (comparedto.equals("projectile")) {
return bEntity instanceof Projectile;
}
else if (comparedto.equals("hanging")) {
return bEntity instanceof Hanging;
}
else if (comparedto.equals("monster")) {
return bEntity instanceof Monster;
}
else if (comparedto.equals("mob")) {
return bEntity instanceof Mob;
}
else if (comparedto.equals("animal")) {
return bEntity instanceof Animals;
switch (comparedto) {
case "entity":
return true;
case "npc":
return entity.isCitizensNPC();
case "player":
return entity.isPlayer();
case "vehicle":
return bEntity instanceof Vehicle;
case "fish":
return bEntity instanceof Fish;
case "projectile":
return bEntity instanceof Projectile;
case "hanging":
return bEntity instanceof Hanging;
case "monster":
return bEntity instanceof Monster;
case "mob":
return bEntity instanceof Mob;
case "animal":
return bEntity instanceof Animals;
}
}
if (comparedto.contains(":")) {
Expand Down
Expand Up @@ -102,14 +102,13 @@ public void cancellationChanged() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("new_material")) {
return new_material;
}
else if (name.equals("old_material")) {
return old_material;
switch (name) {
case "location":
return location;
case "new_material":
return new_material;
case "old_material":
return old_material;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -121,14 +121,13 @@ else if (ItemTag.matches(determination)) {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("item")) {
return item;
}
else if (name.equals("velocity")) {
return new LocationTag(event.getVelocity());
switch (name) {
case "location":
return location;
case "item":
return item;
case "velocity":
return new LocationTag(event.getVelocity());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -75,14 +75,13 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return material;
}
else if (name.equals("source_location")) {
return new LocationTag(event.getBlock().getLocation());
switch (name) {
case "location":
return location;
case "material":
return material;
case "source_location":
return new LocationTag(event.getBlock().getLocation());
}
return super.getContext(name);
}
Expand Down

0 comments on commit 7746cf8

Please sign in to comment.