Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/resources/config.yml
  • Loading branch information
gdude2002 committed Mar 24, 2015
2 parents 6cbe2d2 + c8306f0 commit 9ad2a44
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 35 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/archivesmc/archblock/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.archivesmc.archblock.commands.*;
import com.archivesmc.archblock.config.MainConfig;
import com.archivesmc.archblock.events.*;
import com.archivesmc.archblock.events.protection.BlockBreakEvent;
import com.archivesmc.archblock.events.protection.BlockPlaceEvent;
import com.archivesmc.archblock.events.protection.PistonMoveEvent;
import com.archivesmc.archblock.events.protection.PlayerInteractEvent;
import com.archivesmc.archblock.events.protection.*;
import com.archivesmc.archblock.importers.WatchBlockImporter;
import com.archivesmc.archblock.integrations.WorldGuard;
import com.mewin.WGCustomFlags.WGCustomFlagsPlugin;
Expand Down Expand Up @@ -107,6 +104,7 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new BlockBreakEvent(this), this);
this.getServer().getPluginManager().registerEvents(new BlockPlaceEvent(this), this);
this.getServer().getPluginManager().registerEvents(new PistonMoveEvent(this), this);
this.getServer().getPluginManager().registerEvents(new PlayerBucketEmpty(this), this);
this.getServer().getPluginManager().registerEvents(new PlayerConnectEvent(this), this);
this.getServer().getPluginManager().registerEvents(new PlayerInteractEvent(this), this);

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/archivesmc/archblock/api/ArchBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,8 @@ public boolean canEditBlock(Block block, Player player) {
return true;
}

if (owner.equals(player.getUniqueId())) {
return true;
}
return owner.equals(player.getUniqueId()) || this.hasFriendship(owner, player.getUniqueId());

return this.hasFriendship(owner, player.getUniqueId());
}

/**
Expand Down Expand Up @@ -368,7 +365,7 @@ public void storePlayer(UUID uuid, String username) {
username = username.toLowerCase();

com.archivesmc.archblock.storage.entities.Player p = new com.archivesmc.archblock.storage.entities.Player(
uuid.toString(), username.toLowerCase()
uuid.toString(), username
);

this.storePlayer(p);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.archivesmc.archblock.events.protection;

import com.archivesmc.archblock.Plugin;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBucketEmptyEvent;

import java.util.UUID;

public class PlayerBucketEmpty implements Listener {
private final Plugin plugin;

public PlayerBucketEmpty(Plugin plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.NORMAL)
public void onEvent(PlayerBucketEmptyEvent event) {
UUID owner = this.plugin.getApi().getOwnerUUID(event.getBlockClicked());
UUID ourUuid = event.getPlayer().getUniqueId();

if (this.plugin.getWorldGuardIntegration().isInIgnoredRegion(event.getBlockClicked())) {
this.plugin.debug("Region has bypass-protection set to true");
return;
}


if (owner != null && ! owner.equals(ourUuid)) {
if (! event.getPlayer().hasPermission("archblock.bypass") && ! this.plugin.getApi().hasFriendship(owner, ourUuid)) {
event.getPlayer().sendMessage(
String.format(
"%s[%sArchBlock%s]%s You may not empty buckets on blocks owned by %s%s%s.",
ChatColor.LIGHT_PURPLE, ChatColor.GOLD, ChatColor.LIGHT_PURPLE,
ChatColor.RED, ChatColor.AQUA, this.plugin.getApi().getUsernameForUuid(owner),
ChatColor.RED
)
);

event.setCancelled(true);
return;
}
this.plugin.debug("Owner is different but player has a bypass or is friends with the owner");
}

this.plugin.debug("Everything's okay - empty ze bucket");
this.plugin.getApi().removeOwner(event.getBlockClicked());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,58 @@ public void run() {
Object uuid, username;
Query q;

q = s.createQuery("SELECT p.uuid FROM Player p WHERE username=:username");
q.setString("username", this.player.getUsername());
uuid = q.uniqueResult();

q = s.createQuery("SELECT p.username FROM Player p WHERE uuid=:uuid");
q.setString("uuid", this.player.getUuid());
username = q.uniqueResult();

if (this.player.getUuid().equalsIgnoreCase((String) uuid)) {
// If the UUID was found..
if (! this.player.getUsername().equalsIgnoreCase((String) username)) {
// If the username wasn't found..
q = s.createQuery("UPDATE Player p SET p.username=:username WHERE p.uuid=:uuid");
q.setString("username", this.player.getUsername());
q.setString("uuid", (String) uuid);
q.executeUpdate();
}
if (username == null) {
// Their UUID isn't in the database, let's check for their username.

this.plugin.debug("UUID isn't in the database.");
} else if (this.player.getUsername().equalsIgnoreCase((String) username)) {
// Their username and UUID matches.

s.flush();
s.close();
return;
} else {
// If the UUID wasn't found..
if (this.player.getUsername().equalsIgnoreCase((String) username)) {
// If the username was found..
q = s.createQuery("UPDATE Player p SET p.uuid=:uuid WHERE p.username=:username");
q.setString("username", this.player.getUsername());
q.setString("uuid", (String) uuid);
q.executeUpdate();
} else {
// If the username wasn't found..
s.save(this.player);
}
// Their UUID is there, but the username is wrong. Update it.

q = s.createQuery("UPDATE Player p SET p.username=:username WHERE p.uuid=:uuid");
q.setString("username", this.player.getUsername().toLowerCase());
q.setString("uuid", this.player.getUuid());
q.executeUpdate();

s.flush();
s.close();
return;
}

s.flush();
s.close();
q = s.createQuery("SELECT p.uuid FROM Player p WHERE username=:username");
q.setString("username", this.player.getUsername().toLowerCase());
uuid = q.uniqueResult();

if (uuid == null) {
// Their username isn't in the database either. Store them.

s.save(this.player);
s.flush();
s.close();
} else if (this.player.getUuid().equalsIgnoreCase((String) uuid)) {
// Their username and UUID matches.

s.flush();
s.close();
} else {
// Their username is there, but the UUID is wrong. Update it.

q = s.createQuery("UPDATE Player p SET p.uuid=:uuid WHERE p.username=:username");
q.setString("username", this.player.getUsername().toLowerCase());
q.setString("uuid", this.player.getUuid());
q.executeUpdate();

s.flush();
s.close();
}
}
}

0 comments on commit 9ad2a44

Please sign in to comment.