Untested 1.7.8 support with minor preparations towards id changes.
This commit is contained in:
parent
b5a98f82c9
commit
9fdf1b1235
@ -8,7 +8,7 @@ import java.util.Map.Entry;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.massivecraft.mcore.cmd.MCommand;
|
import com.massivecraft.mcore.cmd.MCommand;
|
||||||
|
@ -1,134 +0,0 @@
|
|||||||
package com.massivecraft.mcore;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
|
||||||
import com.massivecraft.mcore.util.Txt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In minecraft a player name is case insensitive but has one and only one correct casing when written out.
|
|
||||||
* The correct casing is decided upon buying minecraft.
|
|
||||||
* If you register "Steve" noone else can register "stEvE".
|
|
||||||
*
|
|
||||||
* If you then try to log in using "STEVE" in the minecraft launcher the name will be corrected to "Steve".
|
|
||||||
* This feature does however only work in online mode.
|
|
||||||
*
|
|
||||||
* If you use a cracked client and an offline mode server you may log on to the server using both "Steve" and "STEVE".
|
|
||||||
* This cause unintended side effects. Some file systems (windows) are case insensitive and some (unix) are case sensitive.
|
|
||||||
* On Unix "Steve" and "STEVE" would have different inventories, locations etc. They would be considered different players.
|
|
||||||
* That would be confusing for the players.
|
|
||||||
* They would seem to lose their inventory when mistyping their name and this would only happen on some servers (those using unix).
|
|
||||||
*
|
|
||||||
* Additionally plugins may start acting weird if this rule is broken.
|
|
||||||
*
|
|
||||||
* The purpose of this "engine" is to enforce the use of the one and same casing for offline mode servers.
|
|
||||||
* You "register" the correct casing at the first login.
|
|
||||||
* After that you get kicked when using an incorrect casing.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EngineOfflineCase extends EngineAbstract
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE & CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static EngineOfflineCase i = new EngineOfflineCase();
|
|
||||||
public static EngineOfflineCase get() { return i; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Plugin getPlugin()
|
|
||||||
{
|
|
||||||
return MCore.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void activate()
|
|
||||||
{
|
|
||||||
super.activate();
|
|
||||||
|
|
||||||
this.lowerToCorrect.clear();
|
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
this.registerCase(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String pdname : MUtil.getPlayerDirectoryNames())
|
|
||||||
{
|
|
||||||
this.registerCase(pdname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private Map<String, String> lowerToCorrect = new HashMap<String, String>();
|
|
||||||
|
|
||||||
private void registerCase(String playerName)
|
|
||||||
{
|
|
||||||
this.lowerToCorrect.put(playerName.toLowerCase(), playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// LISTENER
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void forceOnePlayerNameCase(PlayerLoginEvent event)
|
|
||||||
{
|
|
||||||
// Stop if the feature is disabled
|
|
||||||
if (!MCoreConf.get().forcingOnePlayerNameCase) return;
|
|
||||||
|
|
||||||
// Stop if we are using online mode
|
|
||||||
if (Bukkit.getOnlineMode()) return;
|
|
||||||
|
|
||||||
// Prepare some variables
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
final String playerName = player.getName();
|
|
||||||
final String playerNameLower = playerName.toLowerCase();
|
|
||||||
|
|
||||||
// Kick if the player already is online
|
|
||||||
// NOTE: Bukkit.getPlayerExact is case insensitive as it should be
|
|
||||||
final Player onlinePlayer = Bukkit.getPlayerExact(playerName);
|
|
||||||
if (onlinePlayer != null)
|
|
||||||
{
|
|
||||||
event.setResult(Result.KICK_OTHER);
|
|
||||||
event.setKickMessage(Txt.parse("<b>The player <h>%s <b>is already online.", onlinePlayer.getName()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consider dat case!
|
|
||||||
String correct = this.lowerToCorrect.get(playerNameLower);
|
|
||||||
if (correct == null)
|
|
||||||
{
|
|
||||||
// "Register"
|
|
||||||
this.registerCase(playerName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Kick if the case is wrong
|
|
||||||
if (!correct.equals(playerName))
|
|
||||||
{
|
|
||||||
event.setResult(Result.KICK_OTHER);
|
|
||||||
event.setKickMessage(Txt.parse("<b>Invalid uppercase and lowercase letters in name.\n<i>Please spell this name like \"<h>%s<i>\".", correct));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -148,7 +148,6 @@ public class MCore extends MPlugin
|
|||||||
EngineScheduledTeleport.get().activate();
|
EngineScheduledTeleport.get().activate();
|
||||||
EngineTeleportMixinCause.get().activate();
|
EngineTeleportMixinCause.get().activate();
|
||||||
EngineWorldNameSet.get().activate();
|
EngineWorldNameSet.get().activate();
|
||||||
EngineOfflineCase.get().activate();
|
|
||||||
EngineCommandRegistration.get().activate(); // TODO: Make all engines
|
EngineCommandRegistration.get().activate(); // TODO: Make all engines
|
||||||
PlayerUtil.get().setup();
|
PlayerUtil.get().setup();
|
||||||
|
|
||||||
|
@ -32,8 +32,6 @@ public class MCoreConf extends Entity<MCoreConf>
|
|||||||
|
|
||||||
public boolean usingRecipientChatEvent = true;
|
public boolean usingRecipientChatEvent = true;
|
||||||
|
|
||||||
public boolean forcingOnePlayerNameCase = true;
|
|
||||||
|
|
||||||
public Map<String, String> permissionDeniedFormats = MUtil.map(
|
public Map<String, String> permissionDeniedFormats = MUtil.map(
|
||||||
"some.awesome.permission.node", "<b>You must be awesome to %s<b>.",
|
"some.awesome.permission.node", "<b>You must be awesome to %s<b>.",
|
||||||
"some.derp.permission.node.1", "derp",
|
"some.derp.permission.node.1", "derp",
|
||||||
|
@ -2,8 +2,8 @@ package com.massivecraft.mcore.adapter;
|
|||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventoryCustom;
|
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryCustom;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventoryPlayer;
|
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryPlayer;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
79
src/com/massivecraft/mcore/cmd/arg/ARBiome.java
Normal file
79
src/com/massivecraft/mcore/cmd/arg/ARBiome.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package com.massivecraft.mcore.cmd.arg;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class ARBiome extends ARAbstractSelect<Biome>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static ARBiome i = new ARBiome();
|
||||||
|
public static ARBiome get() { return i; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typename()
|
||||||
|
{
|
||||||
|
return "biome";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Biome select(String arg, CommandSender sender)
|
||||||
|
{
|
||||||
|
arg = getComparable(arg);
|
||||||
|
|
||||||
|
String biomestr;
|
||||||
|
for (Biome biome : Biome.values())
|
||||||
|
{
|
||||||
|
biomestr = getComparable(biome.name());
|
||||||
|
if (biomestr.equals(arg))
|
||||||
|
{
|
||||||
|
return biome;
|
||||||
|
}
|
||||||
|
|
||||||
|
biomestr = String.valueOf(biome.ordinal());
|
||||||
|
if (biomestr.equals(arg))
|
||||||
|
{
|
||||||
|
return biome;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> altNames(CommandSender sender)
|
||||||
|
{
|
||||||
|
List<String> ret = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (Biome biome : Biome.values())
|
||||||
|
{
|
||||||
|
ret.add(String.valueOf(biome.ordinal()));
|
||||||
|
ret.add(biome.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// UTIL
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static String getComparable(String str)
|
||||||
|
{
|
||||||
|
str = str.toLowerCase();
|
||||||
|
str = str.replace("_", "");
|
||||||
|
str = str.replace(" ", "");
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package com.massivecraft.mcore.inventory;
|
package com.massivecraft.mcore.inventory;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityHuman;
|
import net.minecraft.server.v1_7_R3.EntityHuman;
|
||||||
import net.minecraft.server.v1_7_R2.ItemStack;
|
import net.minecraft.server.v1_7_R3.ItemStack;
|
||||||
import net.minecraft.server.v1_7_R2.PlayerInventory;
|
import net.minecraft.server.v1_7_R3.PlayerInventory;
|
||||||
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ import org.bukkit.inventory.InventoryHolder;
|
|||||||
* pickup(ItemStack) (2 matches)
|
* pickup(ItemStack) (2 matches)
|
||||||
* PlayerInventory(EntityHuman)
|
* PlayerInventory(EntityHuman)
|
||||||
*
|
*
|
||||||
* As of 1.6.1 and 1.6.2 and 1.6.4 and 1.7.2 and 1.7.5 these are the references:
|
* As of 1.6.1 and 1.6.2 and 1.6.4 and 1.7.2 and 1.7.5 and 1.7.8 these are the references:
|
||||||
*
|
*
|
||||||
* a(EntityHuman) (2 matches)
|
* a(EntityHuman) (2 matches)
|
||||||
* a(float)
|
* a(float)
|
||||||
|
@ -3,10 +3,11 @@ package com.massivecraft.mcore.mixin;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
|
|
||||||
public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
||||||
{
|
{
|
||||||
public final static ChatColor DEFAULT_COLOR = ChatColor.WHITE;
|
public final static ChatColor DEFAULT_COLOR = ChatColor.WHITE;
|
||||||
@ -39,7 +40,7 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
|||||||
// Try Bukkit
|
// Try Bukkit
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
Player player = Bukkit.getPlayerExact(senderId);
|
Player player = SenderUtil.getPlayer(senderId);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
ret = player.getDisplayName();
|
ret = player.getDisplayName();
|
||||||
@ -73,7 +74,7 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
|||||||
this.idToDisplayName.put(senderId, displayName);
|
this.idToDisplayName.put(senderId, displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = Bukkit.getPlayerExact(senderId);
|
Player player = SenderUtil.getPlayer(senderId);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
player.setDisplayName(this.getDisplayName(senderId));
|
player.setDisplayName(this.getDisplayName(senderId));
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@ package com.massivecraft.mcore.mixin;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
|
|
||||||
public class ListNameMixinDefault extends ListNameMixinAbstract
|
public class ListNameMixinDefault extends ListNameMixinAbstract
|
||||||
{
|
{
|
||||||
public final static ChatColor DEFAULT_COLOR = ChatColor.WHITE;
|
public final static ChatColor DEFAULT_COLOR = ChatColor.WHITE;
|
||||||
@ -39,7 +40,7 @@ public class ListNameMixinDefault extends ListNameMixinAbstract
|
|||||||
// Try Bukkit
|
// Try Bukkit
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
Player player = Bukkit.getPlayerExact(senderId);
|
Player player = SenderUtil.getPlayer(senderId);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
ret = player.getPlayerListName();
|
ret = player.getPlayerListName();
|
||||||
@ -73,7 +74,7 @@ public class ListNameMixinDefault extends ListNameMixinAbstract
|
|||||||
this.idToListName.put(senderId, listName);
|
this.idToListName.put(senderId, listName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = Bukkit.getPlayerExact(senderId);
|
Player player = SenderUtil.getPlayer(senderId);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
player.setPlayerListName(this.getListName(senderId));
|
player.setPlayerListName(this.getListName(senderId));
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
|
||||||
|
|
||||||
public class PlayedMixinDefault extends PlayedMixinAbstract
|
public class PlayedMixinDefault extends PlayedMixinAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -41,13 +37,10 @@ public class PlayedMixinDefault extends PlayedMixinAbstract
|
|||||||
{
|
{
|
||||||
if (this.isOnline(senderId)) return System.currentTimeMillis();
|
if (this.isOnline(senderId)) return System.currentTimeMillis();
|
||||||
|
|
||||||
String playerNameCC = Mixin.reqFix(senderId);
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(senderId);
|
||||||
if (playerNameCC == null) return null;
|
Long ret = offlinePlayer.getLastPlayed();
|
||||||
|
if (ret == 0) ret = null;
|
||||||
File playerFile = new File(MUtil.getPlayerDirectory(), playerNameCC+".dat");
|
return ret;
|
||||||
long lastModified = playerFile.lastModified();
|
|
||||||
if (lastModified == 0) return null;
|
|
||||||
return lastModified;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ import com.massivecraft.mcore.MCore;
|
|||||||
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
|
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
|
||||||
import com.massivecraft.mcore.event.MCoreSenderRegisterEvent;
|
import com.massivecraft.mcore.event.MCoreSenderRegisterEvent;
|
||||||
import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
import com.massivecraft.mcore.util.PlayerUtil;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ public class SenderIdMixinDefault extends SenderIdMixinAbstract implements Liste
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add offline players
|
// Add offline players
|
||||||
for (String id : MUtil.getPlayerDirectoryNames())
|
for (String id : PlayerUtil.getDirectoryPlayerNames())
|
||||||
{
|
{
|
||||||
// Check if this player was added already since it's online
|
// Check if this player was added already since it's online
|
||||||
if (this.onlinePlayerIds.contains(id)) continue;
|
if (this.onlinePlayerIds.contains(id)) continue;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
|
|
||||||
public class SenderPsMixinDefault extends SenderPsMixinAbstract
|
public class SenderPsMixinDefault extends SenderPsMixinAbstract
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ public class SenderPsMixinDefault extends SenderPsMixinAbstract
|
|||||||
@Override
|
@Override
|
||||||
public PS getSenderPs(String senderId)
|
public PS getSenderPs(String senderId)
|
||||||
{
|
{
|
||||||
Player player = Bukkit.getPlayerExact(senderId);
|
Player player = SenderUtil.getPlayer(senderId);
|
||||||
if (player == null) return null;
|
if (player == null) return null;
|
||||||
return PS.valueOf(player.getLocation());
|
return PS.valueOf(player.getLocation());
|
||||||
}
|
}
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package com.massivecraft.mcore.util;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.BiomeBase;
|
|
||||||
import net.minecraft.server.v1_7_R2.Chunk;
|
|
||||||
import net.minecraft.server.v1_7_R2.WorldServer;
|
|
||||||
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
|
|
||||||
|
|
||||||
public class BiomeUtil
|
|
||||||
{
|
|
||||||
public static Map<Integer, String> getBiomeIdNames()
|
|
||||||
{
|
|
||||||
Map<Integer, String> ret = new LinkedHashMap<Integer, String>();
|
|
||||||
for (BiomeBase bb : BiomeBase.n())
|
|
||||||
{
|
|
||||||
if (bb == null) continue;
|
|
||||||
ret.put(bb.id, bb.af);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Entry<Integer, String> getBiomeIdAndNameAt(World world, int x, int z)
|
|
||||||
{
|
|
||||||
CraftWorld craftWorld = (CraftWorld)world;
|
|
||||||
WorldServer worldServer = craftWorld.getHandle();
|
|
||||||
|
|
||||||
BiomeBase biomeBase = worldServer.getBiome(x, z);
|
|
||||||
|
|
||||||
Integer id = biomeBase.id;
|
|
||||||
String name = biomeBase.af;
|
|
||||||
|
|
||||||
return new SimpleEntry<Integer, String>(id, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setBiomeIdAt(World world, int x, int z, int id)
|
|
||||||
{
|
|
||||||
CraftWorld craftWorld = (CraftWorld)world;
|
|
||||||
WorldServer worldServer = craftWorld.getHandle();
|
|
||||||
|
|
||||||
BiomeBase bb = BiomeBase.getBiome(id);
|
|
||||||
if (craftWorld.loadChunk(x >> 4, z >> 4, false)) {
|
|
||||||
Chunk chunk = worldServer.getChunkAtWorldCoords(x, z);
|
|
||||||
|
|
||||||
if (chunk != null) {
|
|
||||||
byte[] biomevals = chunk.m();
|
|
||||||
biomevals[((z & 0xF) << 4) | (x & 0xF)] = (byte)bb.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getBiomeIdAt(World world, int x, int z)
|
|
||||||
{
|
|
||||||
return getBiomeIdAndNameAt(world, x, z).getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBiomeNameAt(World world, int x, int z)
|
|
||||||
{
|
|
||||||
return getBiomeIdAndNameAt(world, x, z).getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,8 +4,8 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventoryCustom;
|
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryCustom;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventoryPlayer;
|
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryPlayer;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.massivecraft.mcore.util;
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.WorldServer;
|
import net.minecraft.server.v1_7_R3.WorldServer;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_7_R3.CraftWorld;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the method by going through CraftBlock.setTypeId()
|
* Find the method by going through CraftBlock.setTypeId()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.massivecraft.mcore.util;
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -19,15 +18,11 @@ import java.util.Set;
|
|||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.DedicatedServer;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
@ -60,58 +55,27 @@ import com.massivecraft.mcore.util.extractor.ExtractorWorldName;
|
|||||||
public class MUtil
|
public class MUtil
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// IS PLAYER ID
|
// IS VALID PLAYER NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// Player id pattern, the regex for a valid minecraft username.
|
// The regex for a valid minecraft player name.
|
||||||
public final static Pattern playerNamePattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$");
|
public final static Pattern playerNamePattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$");
|
||||||
|
|
||||||
public static boolean isValidPlayerName(Object o)
|
public static boolean isValidPlayerName(String string)
|
||||||
{
|
{
|
||||||
if (!(o instanceof String)) return false;
|
return playerNamePattern.matcher(string).matches();
|
||||||
return playerNamePattern.matcher((String) o).matches();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// PLAYER DIRECTORY
|
// IS VALID UUID
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// A way of getting the player directory even when the server just started
|
|
||||||
|
|
||||||
public static File getPlayerDirectory()
|
// The regex for a valid UUID in string form
|
||||||
{
|
public final static Pattern uuidPattern = Pattern.compile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$");
|
||||||
CraftServer cserver = (CraftServer)Bukkit.getServer();
|
|
||||||
DedicatedServer dserver = (DedicatedServer)cserver.getServer();
|
|
||||||
String levelName = dserver.propertyManager.getString("level-name", "world");
|
|
||||||
return new File(Bukkit.getWorldContainer(), new File(levelName, "players").getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getPlayerDirectoryNames()
|
public static boolean isValidUUID(String string)
|
||||||
{
|
{
|
||||||
List<String> ret = new ArrayList<String>();
|
return uuidPattern.matcher(string).matches();
|
||||||
|
|
||||||
// Get the player directory
|
|
||||||
File playerDirectory = getPlayerDirectory();
|
|
||||||
|
|
||||||
// List the files in the player folder
|
|
||||||
File[] playerfiles = playerDirectory.listFiles();
|
|
||||||
|
|
||||||
// The player directory may not exist yet
|
|
||||||
if (playerfiles == null) return ret;
|
|
||||||
|
|
||||||
// Populate by removing .dat
|
|
||||||
for (File playerfile : playerfiles)
|
|
||||||
{
|
|
||||||
String filename = playerfile.getName();
|
|
||||||
|
|
||||||
// Ensure it's actually a .dat player filefile
|
|
||||||
if (!filename.toLowerCase().endsWith(".dat")) continue;
|
|
||||||
|
|
||||||
String playername = filename.substring(0, filename.length()-4);
|
|
||||||
|
|
||||||
ret.add(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.massivecraft.mcore.util;
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -13,11 +17,15 @@ import java.util.TreeSet;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
import net.minecraft.server.v1_7_R3.DedicatedServer;
|
||||||
import net.minecraft.server.v1_7_R2.PacketPlayOutUpdateHealth;
|
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_7_R3.NBTCompressedStreamTools;
|
||||||
|
import net.minecraft.server.v1_7_R3.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_7_R3.PacketPlayOutUpdateHealth;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -153,6 +161,111 @@ public class PlayerUtil implements Listener
|
|||||||
eplayer.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(cplayer.getScaledHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().e()));
|
eplayer.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(cplayer.getScaledHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().e()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// PLAYER DIRECTORIES
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// Getting the player directories even when the server just started.
|
||||||
|
// We also supply ways to pull player names or UUIDs.
|
||||||
|
|
||||||
|
public static File getDirectoryBaseworld()
|
||||||
|
{
|
||||||
|
CraftServer cserver = (CraftServer)Bukkit.getServer();
|
||||||
|
DedicatedServer dserver = (DedicatedServer)cserver.getServer();
|
||||||
|
String levelName = dserver.propertyManager.getString("level-name", "world");
|
||||||
|
return new File(Bukkit.getWorldContainer(), levelName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getDirectoryPlayerdata()
|
||||||
|
{
|
||||||
|
// after 1.7.8
|
||||||
|
// a2cce16b-9494-45ff-b5ff-0362ca687d4e.dat (the uuid)
|
||||||
|
return new File(getDirectoryBaseworld(), "playerdata");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<UUID> getDirectoryPlayerIds()
|
||||||
|
{
|
||||||
|
List<UUID> ret = new ArrayList<UUID>();
|
||||||
|
|
||||||
|
// Get the directory
|
||||||
|
File directory = getDirectoryPlayerdata();
|
||||||
|
|
||||||
|
// List the files in the directory
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
|
||||||
|
// The directory may not exist
|
||||||
|
if (files == null) return ret;
|
||||||
|
|
||||||
|
// Populate by removing .dat
|
||||||
|
for (File file : files)
|
||||||
|
{
|
||||||
|
String filename = file.getName();
|
||||||
|
|
||||||
|
// Ensure it's actually a .dat player filefile
|
||||||
|
if (!filename.toLowerCase().endsWith(".dat")) continue;
|
||||||
|
|
||||||
|
String uuid = filename.substring(0, filename.length()-4);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.add(UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getDirectoryPlayerNames()
|
||||||
|
{
|
||||||
|
List<String> ret = new ArrayList<String>();
|
||||||
|
|
||||||
|
// Get the directory
|
||||||
|
File directory = getDirectoryPlayerdata();
|
||||||
|
|
||||||
|
// List the files in the directory
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
|
||||||
|
// The directory may not exist
|
||||||
|
if (files == null) return ret;
|
||||||
|
|
||||||
|
// For each file
|
||||||
|
for (File file : files)
|
||||||
|
{
|
||||||
|
NBTTagCompound compound = loadTagCompound(file);
|
||||||
|
if (compound == null) continue;
|
||||||
|
|
||||||
|
if (!compound.hasKey("bukkit")) continue;
|
||||||
|
NBTTagCompound bukkit = compound.getCompound("bukkit");
|
||||||
|
if (bukkit == null) continue;
|
||||||
|
|
||||||
|
if (!bukkit.hasKey("lastKnownName")) continue;
|
||||||
|
String lastKnownName = bukkit.getString("lastKnownName");
|
||||||
|
if (lastKnownName == null) continue;
|
||||||
|
|
||||||
|
ret.add(lastKnownName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NBTTagCompound loadTagCompound(File file)
|
||||||
|
{
|
||||||
|
if (!file.exists()) return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return NBTCompressedStreamTools.a((InputStream) (new FileInputStream(file)));
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// PLAYER ID <---> PLAYER NAME
|
// PLAYER ID <---> PLAYER NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -5,10 +5,11 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.MinecraftServer;
|
import net.minecraft.server.v1_7_R3.MinecraftServer;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -17,7 +18,7 @@ import org.bukkit.command.BlockCommandSender;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
import org.bukkit.command.RemoteConsoleCommandSender;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
@ -26,10 +27,11 @@ import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* We add an ID <--> CommandSender lookup feature.
|
* We add an ID <--> CommandSender lookup feature.
|
||||||
* Each player has an id which is the name of the player. Players are retrievable by id using Bukkit.getPlayerExact().
|
* Each player has an id which is the UUID of the player.
|
||||||
|
* Players are retrievable by id using Bukkit.getPlayer().
|
||||||
* Other command senders have no true id. We make it so they have.
|
* Other command senders have no true id. We make it so they have.
|
||||||
* Non-player-sender-ids always start with and ampersand (@). This is to avoid clashes with regular player names.
|
* Non-player-sender-ids always start with and ampersand (@). This is to avoid clashes with regular player names.
|
||||||
* The id is simply "@"+CommandSender.getName() with exception for the block command sender which we call "@block".
|
* The id is simply "@"+CommandSender.getName()
|
||||||
* Non standard CommandSenders must be manually registered to the util using the register method.
|
* Non standard CommandSenders must be manually registered to the util using the register method.
|
||||||
*/
|
*/
|
||||||
public class SenderUtil
|
public class SenderUtil
|
||||||
@ -54,7 +56,6 @@ public class SenderUtil
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected static Map<String, CommandSender> idToSender = new TreeMap<String, CommandSender>(String.CASE_INSENSITIVE_ORDER);
|
protected static Map<String, CommandSender> idToSender = new TreeMap<String, CommandSender>(String.CASE_INSENSITIVE_ORDER);
|
||||||
protected static Map<String, String> idToListName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
|
|
||||||
public static synchronized boolean register(CommandSender sender)
|
public static synchronized boolean register(CommandSender sender)
|
||||||
{
|
{
|
||||||
@ -82,7 +83,7 @@ public class SenderUtil
|
|||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
// Since the console and rcon does not exist we schedule the register for these senders.
|
// Since the console and rcon initially does not exist we schedule the register for these senders.
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.get(), new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.get(), new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -100,12 +101,15 @@ public class SenderUtil
|
|||||||
|
|
||||||
public static boolean isSenderId(Object o)
|
public static boolean isSenderId(Object o)
|
||||||
{
|
{
|
||||||
return o instanceof String;
|
return o instanceof String || o instanceof UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlayerId(Object o)
|
public static boolean isPlayerId(Object o)
|
||||||
{
|
{
|
||||||
return MUtil.isValidPlayerName(o);
|
if (o instanceof UUID) return true;
|
||||||
|
if (!(o instanceof String)) return false;
|
||||||
|
String string = (String)o;
|
||||||
|
return MUtil.isValidPlayerName(string) || MUtil.isValidUUID(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConsoleId(Object o)
|
public static boolean isConsoleId(Object o)
|
||||||
@ -162,6 +166,7 @@ public class SenderUtil
|
|||||||
// GET ID
|
// GET ID
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// TODO: Returns outdated value (name instead of ID)
|
||||||
public static String getSenderId(Object o)
|
public static String getSenderId(Object o)
|
||||||
{
|
{
|
||||||
if (!isSender(o)) return null;
|
if (!isSender(o)) return null;
|
||||||
@ -177,13 +182,22 @@ public class SenderUtil
|
|||||||
|
|
||||||
// ACTUALL LOGIC
|
// ACTUALL LOGIC
|
||||||
|
|
||||||
|
// Note: Handles both player id and name.
|
||||||
public static synchronized CommandSender getSender(String senderId)
|
public static synchronized CommandSender getSender(String senderId)
|
||||||
{
|
{
|
||||||
if (senderId == null) return null;
|
if (senderId == null) return null;
|
||||||
if (isPlayerId(senderId))
|
|
||||||
|
if (MUtil.isValidPlayerName(senderId))
|
||||||
{
|
{
|
||||||
return Bukkit.getPlayerExact(senderId);
|
return Bukkit.getPlayerExact(senderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MUtil.isValidUUID(senderId))
|
||||||
|
{
|
||||||
|
UUID uuid = UUID.fromString(senderId);
|
||||||
|
return Bukkit.getPlayer(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
return idToSender.get(senderId);
|
return idToSender.get(senderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user