Skip to content

Commit

Permalink
Use get directly and check for null
Browse files Browse the repository at this point in the history
Saves one hash table lookup
  • Loading branch information
niekschoemaker committed Aug 5, 2024
1 parent e4e19f8 commit 85afa00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ private <T extends Cancellable> void handleEvent(T e, Entity entity, Entity dama
damager.remove();
}

long lastNotification = 0;
if ( d.has("LAST_FRIENDLYFIRE_NOTIFICATION") ) {
lastNotification = d.get("LAST_FRIENDLYFIRE_NOTIFICATION", Long.class);
Long lastNotification = d.get("LAST_FRIENDLYFIRE_NOTIFICATION", Long.class);
if ( lastNotification == null ) {
lastNotification = 0L;
}

if ( System.currentTimeMillis() - lastNotification > 5000 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public void onReload(PluginReloadEvent e) {
//

void clear(PlatformPlayer player) {
if ( !player.has(PERMISSIONS_KEY) ) {
PermissionAttachment pa = player.get(PERMISSIONS_KEY, PermissionAttachment.class);
if ( pa == null ) {
return;
}

PermissionAttachment pa = player.get(PERMISSIONS_KEY, PermissionAttachment.class);
Player p = ((BukkitPlayer) player).getPlayer();
p.removeAttachment(pa);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public MenuChatListener(KingdomCraftBukkitPlugin plugin) {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) {
PlatformPlayer player = plugin.getKdc().getPlayer(event.getPlayer().getUniqueId());
Consumer<String> c = (Consumer<String>)player.get("MENU_CHAT_CALLBACK", Consumer.class);

if ( !player.has("MENU_CHAT_CALLBACK") ) {
if ( c == null ) {
return;
}

event.setCancelled(true);

Consumer c = player.get("MENU_CHAT_CALLBACK", Consumer.class);
player.remove("MENU_CHAT_CALLBACK");

if ( !event.getMessage().equalsIgnoreCase("cancel") ) {
Expand All @@ -59,11 +59,12 @@ public void onChat(AsyncPlayerChatEvent event) {

player.sendMessage(ChatColor.GREEN + "Cancelled!");

if ( !player.has("MENU_CHAT_CANCEL") ) {
Runnable r = player.get("MENU_CHAT_CANCEL", Runnable.class);

if ( r == null ) {
return;
}

Runnable r = player.get("MENU_CHAT_CANCEL", Runnable.class);
plugin.getScheduler().sync().execute(() -> r.run());

player.remove("MENU_CHAT_CANCEL");
Expand Down

0 comments on commit 85afa00

Please sign in to comment.