More UUID changes

This commit is contained in:
Andrzej Pomirski 2014-04-12 13:57:39 +02:00
parent 7321e6dc07
commit 4107b10f4b
23 changed files with 62 additions and 124 deletions

View File

@ -1,12 +1,13 @@
package com.Acrobot.Breeze.Utils;
import org.bukkit.block.*;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.*;
import org.bukkit.material.Attachable;
/**
* @author Acrobot

View File

@ -19,7 +19,10 @@ import com.Acrobot.ChestShop.Listeners.Item.ItemMoveListener;
import com.Acrobot.ChestShop.Listeners.ItemInfoListener;
import com.Acrobot.ChestShop.Listeners.Modules.DiscountModule;
import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule;
import com.Acrobot.ChestShop.Listeners.Player.*;
import com.Acrobot.ChestShop.Listeners.Player.PlayerConnect;
import com.Acrobot.ChestShop.Listeners.Player.PlayerInteract;
import com.Acrobot.ChestShop.Listeners.Player.PlayerInventory;
import com.Acrobot.ChestShop.Listeners.Player.PlayerTeleport;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender;
import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger;
@ -34,8 +37,7 @@ import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRemovalLogger;
import com.Acrobot.ChestShop.Logging.FileFormatter;
import com.Acrobot.ChestShop.Metadata.ItemDatabase;
import com.Acrobot.ChestShop.Signs.RestrictedSign;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.Utils.uName;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.avaje.ebean.EbeanServer;
import com.lennardf1989.bukkitex.Database;
import com.nijikokun.register.payment.forChestShop.Methods;
@ -86,10 +88,7 @@ public class ChestShop extends JavaPlugin {
itemDatabase = new ItemDatabase();
uName.file = loadFile("longName.storage");
uName.load();
UUIDSaver.load();
NameManager.load();
Methods.setPreferred(Properties.PREFERRED_ECONOMY_PLUGIN);
@ -196,7 +195,6 @@ public class ChestShop extends JavaPlugin {
registerEvent(new ItemInfoListener());
registerEvent(new RestrictedSign());
registerEvent(new ShortNameSaver());
if (!Properties.TURN_OFF_HOPPER_PROTECTION) {
registerEvent(new ItemMoveListener());

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Events.Economy;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -29,7 +29,7 @@ public class CurrencyAddEvent extends Event {
}
public CurrencyAddEvent(BigDecimal amount, Player target) {
this(amount, UUIDSaver.getUsername(target.getUniqueId()), target.getWorld());
this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld());
}
/**

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Events.Economy;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -26,7 +26,7 @@ public class CurrencyAmountEvent extends Event {
}
public CurrencyAmountEvent(Player player) {
this(UUIDSaver.getUsername(player.getUniqueId()), player.getWorld());
this(NameManager.getUsername(player.getUniqueId()), player.getWorld());
}
/**

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Events.Economy;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -29,7 +29,7 @@ public class CurrencyCheckEvent extends Event {
}
public CurrencyCheckEvent(BigDecimal amount, Player player) {
this(amount, UUIDSaver.getUsername(player.getUniqueId()), player.getWorld());
this(amount, NameManager.getUsername(player.getUniqueId()), player.getWorld());
}
/**

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Events.Economy;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -29,7 +29,7 @@ public class CurrencyHoldEvent extends Event {
}
public CurrencyHoldEvent(BigDecimal amount, Player target) {
this(amount, UUIDSaver.getUsername(target.getUniqueId()), target.getWorld());
this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld());
}
/**

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Events.Economy;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -29,7 +29,7 @@ public class CurrencySubtractEvent extends Event {
}
public CurrencySubtractEvent(BigDecimal amount, Player target) {
this(amount, UUIDSaver.getUsername(target.getUniqueId()), target.getWorld());
this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld());
}
/**

View File

@ -38,7 +38,7 @@ import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
import static com.Acrobot.ChestShop.Permission.ADMIN;
import static com.Acrobot.ChestShop.Permission.MOD;
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
import static com.Acrobot.ChestShop.Utils.uName.canUseName;
import static com.Acrobot.ChestShop.UUIDs.NameManager.canUseName;
/**
* @author Acrobot

View File

@ -3,7 +3,7 @@ package com.Acrobot.ChestShop.Listeners.Player;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@ -30,6 +30,6 @@ public class PlayerConnect implements Listener {
@EventHandler
public static void onPlayerConnect(PlayerJoinEvent event) {
UUIDSaver.storeUsername(event.getPlayer());
NameManager.storeUsername(event.getPlayer());
}
}

View File

@ -10,7 +10,7 @@ import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Plugins.ChestShop;
import com.Acrobot.ChestShop.Security;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -115,8 +115,8 @@ public class PlayerInteract implements Listener {
String prices = sign.getLine(PRICE_LINE);
String material = sign.getLine(ITEM_LINE);
String ownerName = UUIDSaver.getFullUsername(name);
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUIDSaver.getUUID(ownerName));
String ownerName = NameManager.getFullUsername(name);
OfflinePlayer owner = Bukkit.getOfflinePlayer(NameManager.getUUID(ownerName));
Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;
double price = (action == buy ? PriceUtil.getBuyPrice(prices) : PriceUtil.getSellPrice(prices));

View File

@ -1,16 +0,0 @@
package com.Acrobot.ChestShop.Listeners.Player;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Utils.uName;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* @author Acrobot
*/
public class ShortNameSaver implements Listener {
@EventHandler
public static void onShopCreated(ShopCreatedEvent event) {
uName.saveName(event.getPlayer().getName());
}
}

View File

@ -4,7 +4,7 @@ import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
import com.Acrobot.ChestShop.Events.TransactionEvent;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -24,7 +24,7 @@ public class EconomicModule implements Listener {
}
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()),
UUIDSaver.getUsername(event.getOwner().getUniqueId()),
NameManager.getUsername(event.getOwner().getUniqueId()),
event.getSign().getWorld());
ChestShop.callEvent(currencyAddEvent);
@ -39,7 +39,7 @@ public class EconomicModule implements Listener {
}
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()),
UUIDSaver.getUsername(event.getOwner().getUniqueId()),
NameManager.getUsername(event.getOwner().getUniqueId()),
event.getSign().getWorld());
ChestShop.callEvent(currencySubtractEvent);

View File

@ -6,7 +6,7 @@ import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.TransactionEvent;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.google.common.base.Joiner;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -89,7 +89,7 @@ public class TransactionMessageSender implements Listener {
private static void sendMessageToOwner(String message, TransactionEvent event) {
String owner = event.getOwner().getName();
owner = UUIDSaver.getFullUsername(owner);
owner = NameManager.getFullUsername(owner);
Player player = Bukkit.getPlayerExact(owner);

View File

@ -1,8 +1,9 @@
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
import com.Acrobot.Breeze.Utils.NameUtil;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Utils.uName;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -20,8 +21,12 @@ public class NameChecker implements Listener {
String name = event.getSignLine(NAME_LINE);
Player player = event.getPlayer();
if (name.isEmpty() || (!uName.canUseName(player, name) && !Permission.has(player, Permission.ADMIN))) {
String shortName = uName.stripName(player);
if (name.isEmpty()) {
return;
}
if (!NameManager.canUseName(player, name) && !Permission.has(player, Permission.ADMIN)) {
String shortName = NameUtil.stripUsername(NameManager.getUsername(player.getUniqueId()));
event.setSignLine(NAME_LINE, shortName);
}
}

View File

@ -4,7 +4,7 @@ import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
@ -53,7 +53,7 @@ public class AmountAndPriceChecker implements Listener {
Inventory clientInventory = event.getClientInventory();
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(event.getPrice()),
UUIDSaver.getUsername(event.getOwner().getUniqueId()),
NameManager.getUsername(event.getOwner().getUniqueId()),
event.getSign().getWorld());
ChestShop.callEvent(currencyCheckEvent);

View File

@ -8,7 +8,7 @@ import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyHoldEvent;
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -61,7 +61,7 @@ public class PartialTransactionModule implements Listener {
event.setStock(getCountedItemStack(stock, amountAffordable));
}
String seller = UUIDSaver.getUsername(event.getOwner().getUniqueId());
String seller = NameManager.getUsername(event.getOwner().getUniqueId());
CurrencyHoldEvent currencyHoldEvent = new CurrencyHoldEvent(BigDecimal.valueOf(price), seller, client.getWorld());
ChestShop.callEvent(currencyHoldEvent);
@ -94,7 +94,7 @@ public class PartialTransactionModule implements Listener {
}
Player client = event.getClient();
String ownerName = UUIDSaver.getUsername(event.getOwner().getUniqueId());
String ownerName = NameManager.getUsername(event.getOwner().getUniqueId());
ItemStack[] stock = event.getStock();
double price = event.getPrice();

View File

@ -7,7 +7,7 @@ import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
import com.Acrobot.ChestShop.Events.ShopDestroyedEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -29,7 +29,7 @@ public class ShopRefundListener implements Listener {
return;
}
String owner = UUIDSaver.getFullUsername(event.getSign().getLine(NAME_LINE));
String owner = NameManager.getFullUsername(event.getSign().getLine(NAME_LINE));
CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), owner, event.getSign().getWorld());
ChestShop.callEvent(currencyEvent);

View File

@ -3,8 +3,8 @@ package com.Acrobot.ChestShop.Plugins;
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uName;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
@ -67,6 +67,6 @@ public class ChestShop implements Listener {
}
private static boolean isShopMember(Player player, Sign sign) {
return uName.canUseName(player, sign.getLine(0));
return NameManager.canUseName(player, sign.getLine(ChestShopSign.NAME_LINE));
}
}

View File

@ -1,7 +1,8 @@
package com.Acrobot.ChestShop.Plugins;
import com.Acrobot.Breeze.Utils.NameUtil;
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
import com.Acrobot.ChestShop.Utils.uName;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -25,7 +26,7 @@ public class Lockette implements Listener {
return;
}
String shortPlayerName = uName.stripName(player);
String shortPlayerName = NameUtil.stripUsername(NameManager.getUsername(player.getUniqueId()));
if (!org.yi.acru.bukkit.Lockette.Lockette.isUser(block, shortPlayerName, true)) {
event.setResult(Event.Result.DENY);

View File

@ -6,7 +6,7 @@ import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.Protection.ProtectBlockEvent;
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.UUIDSaver;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
@ -64,7 +64,7 @@ public class Security {
}
private static boolean anotherShopFound(Block baseBlock, Block signBlock, Player player) {
String playerName = UUIDSaver.getUsername(player.getUniqueId());
String playerName = NameManager.getUsername(player.getUniqueId());
String shortName = NameUtil.stripUsername(playerName);
for (BlockFace face : SIGN_CONNECTION_FACES) {

View File

@ -3,8 +3,8 @@ package com.Acrobot.ChestShop.Signs;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Containers.AdminInventory;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uName;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
@ -81,7 +81,7 @@ public class ChestShopSign {
if (player == null) return false;
if (sign == null) return true;
return uName.canUseName(player, sign.getLine(0));
return NameManager.canUseName(player, sign.getLine(NAME_LINE));
}
public static boolean isValidPreparedSign(String[] lines) {

View File

@ -4,6 +4,7 @@ import com.Acrobot.Breeze.Utils.NameUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Database.Account;
import com.Acrobot.ChestShop.Database.ConnectionManager;
import com.Acrobot.ChestShop.Permission;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
@ -20,7 +21,7 @@ import java.util.UUID;
*
* @author Andrzej Pomirski (Acrobot)
*/
public class UUIDSaver {
public class NameManager {
private static Dao<Account, String> accounts;
public static UUID getUUID(String username) {
@ -102,6 +103,12 @@ public class UUIDSaver {
}
}
public static boolean canUseName(Player player, String name) {
String shortenedName = NameUtil.stripUsername(getUsername(player.getUniqueId()));
return shortenedName.equals(name) || Permission.otherName(player, name);
}
public static void load() {
File databaseFile = ChestShop.loadFile("users.db");
String uri = ConnectionManager.getURI(databaseFile);

View File

@ -1,58 +0,0 @@
package com.Acrobot.ChestShop.Utils;
import com.Acrobot.ChestShop.Permission;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
/**
* @author Acrobot
*/
public class uName {
public static YamlConfiguration config;
public static File file;
public static String getName(String shortName) {
return config.getString(shortName, shortName);
}
public static void saveName(String name) {
if (name.length() <= 15) {
return;
}
config.set(stripName(name), name);
reload();
}
public static String stripName(String name) {
if (name.length() > 15) {
return name.substring(0, 15);
}
return name;
}
public static String stripName(Player player) {
return stripName(player.getName());
}
public static boolean canUseName(Player player, String name) {
return stripName(player).equals(name) || Permission.otherName(player, name);
}
public static void load() {
config = YamlConfiguration.loadConfiguration(file);
}
public static void reload() {
try {
config.save(file);
} catch (IOException e) {
e.printStackTrace();
}
load();
}
}