Initial commit
This commit is contained in:
176
src/de/anura/core/API.java
Normal file
176
src/de/anura/core/API.java
Normal file
@@ -0,0 +1,176 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class API {
|
||||
|
||||
/**
|
||||
* Use this if you want to change the language
|
||||
*/
|
||||
public final static HashMap<Player, String> cachedPlayerLanguage = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the current MySQL Object
|
||||
* @return The working MySQL Object
|
||||
*/
|
||||
public static MySQL getMySql()
|
||||
{
|
||||
if(!AnuraCore.getSql().isValid) return null;
|
||||
return AnuraCore.getSql();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a language value for the given id and language
|
||||
* @param id The language id as used in the translation center
|
||||
* @param lang The short value of a language e.g. de, en
|
||||
* @return Returns the text for this id
|
||||
*/
|
||||
public static String getl(String id, String lang)
|
||||
{
|
||||
String val = AnuraCore.getInstance().lang.get(id, lang);
|
||||
if(val == null || val.equals(""))
|
||||
{
|
||||
val = AnuraCore.getInstance().lang.get(id, "en");
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a language value for the given id for a CommandSender
|
||||
* @param id The language id as used in the translation center
|
||||
* @param cs A command sender to automatically detect the language
|
||||
* @return Returns the text for this id
|
||||
*/
|
||||
public static String getl(String id, CommandSender cs)
|
||||
{
|
||||
if(cs instanceof Player)
|
||||
{
|
||||
return API.getl(id, (Player)cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
return API.getl(id, "en");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a language value for the given id for a Player
|
||||
* @param id The language id as used in the translation center
|
||||
* @param P A player to use his language setting
|
||||
* @return Returns the text for this id
|
||||
*/
|
||||
public static String getl(String id, Player P)
|
||||
{
|
||||
return API.getl(id, API.getPlayerLang(P));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a translated and colored message to the given CommandSender
|
||||
* @param P The CommandSender, whose language is being determined and the language is sended to
|
||||
* @param id The language id as used in the translation center
|
||||
* @param status The type of the message(true for green, false for red)
|
||||
*/
|
||||
public static void statusMsg(CommandSender P, String id, Boolean status)
|
||||
{
|
||||
ChatColor chatColor;
|
||||
if(status) chatColor = ChatColor.GREEN;
|
||||
else chatColor = ChatColor.RED;
|
||||
P.sendMessage(ChatColor.GRAY + "[Anura] "+chatColor+API.getl(id, API.getPlayerLang(P)));
|
||||
}
|
||||
/**
|
||||
* Sends a translated and colored message to the given CommandSender
|
||||
* @param P The CommandSender, whose language is being determined and the language is sended to
|
||||
* @param id The language id as used in the translation center
|
||||
* @param color The color of the message
|
||||
*/
|
||||
public static void statusMsg(CommandSender P, String id, ChatColor color)
|
||||
{
|
||||
P.sendMessage(ChatColor.GRAY + "[Anura] "+color+API.getl(id, API.getPlayerLang(P)));
|
||||
}
|
||||
/**
|
||||
* Returns the language of the given CommandSender
|
||||
* @param P The CommandSender, whose language is being determined
|
||||
* @return Returns the short language name of the player (like de or en)
|
||||
*/
|
||||
public static String getPlayerLang(CommandSender P)
|
||||
{
|
||||
if(!(P instanceof Player))
|
||||
{
|
||||
return "en";
|
||||
}
|
||||
Player p = (Player)P;
|
||||
if(!API.cachedPlayerLanguage.containsKey(p))
|
||||
{
|
||||
ResultSet rs = AnuraCore.sql.querySelect("SELECT lang FROM players WHERE uuid = '"+p.getUniqueId().toString()+"'");
|
||||
try {
|
||||
rs.first();
|
||||
API.cachedPlayerLanguage.put(p, rs.getString("lang"));
|
||||
return rs.getString("lang");
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("SQLException in getPlayerLang of API: "+ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return API.cachedPlayerLanguage.get(p);
|
||||
}
|
||||
return "en";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an extra set of tools
|
||||
* @return Tools
|
||||
*/
|
||||
public static Tools getTools()
|
||||
{
|
||||
return AnuraCore.getInstance().tools;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the available Languages
|
||||
* @return Returns an iterable set of strings like de or en
|
||||
*/
|
||||
public static Set<String> getAvailLangs()
|
||||
{
|
||||
return AnuraCore.getInstance().lang.languages.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Key by a given value from a given HashMap
|
||||
* @param <T> The type of the key in the map
|
||||
* @param <E> The type of the value in the map
|
||||
* @param map The HashMap to get the key from
|
||||
* @param value The value to use to get a key
|
||||
* @return Returns the found key
|
||||
*/
|
||||
public static <T, E> T getKeyByValue(Map<T, E> map, E value) {
|
||||
for (Map.Entry<T, E> entry : map.entrySet()) {
|
||||
if (value.equals(entry.getValue())) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all lobby features for all players from the database
|
||||
*/
|
||||
public static void updateFeatures() {
|
||||
AnuraCore.getInstance().getFeatures().updateFeaturesAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all lobby features for the given player from the database
|
||||
* @param P The player to update the features
|
||||
*/
|
||||
public static void updateFeatures(Player P) {
|
||||
AnuraCore.getInstance().getFeatures().updateFeatures(P);
|
||||
}
|
||||
}
|
||||
1283
src/de/anura/core/AnuraCore.java
Normal file
1283
src/de/anura/core/AnuraCore.java
Normal file
File diff suppressed because it is too large
Load Diff
60
src/de/anura/core/BlockBreak.java
Normal file
60
src/de/anura/core/BlockBreak.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.material.Stairs;
|
||||
|
||||
|
||||
public class BlockBreak implements Listener
|
||||
{
|
||||
public BlockBreak(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if(plugin.getConfig().getBoolean("no-change-blocks"))
|
||||
{
|
||||
if(!event.getPlayer().hasPermission("core.rules.blocks.break"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(plugin.flowerPots.containsValue(event.getBlock().getLocation())) event.setCancelled(true);
|
||||
if((event.getBlock().getType() == Material.ENDER_CHEST || event.getBlock().getType() == Material.RAILS))
|
||||
{
|
||||
int X = (int)event.getBlock().getLocation().getX();
|
||||
int Y = (int)event.getBlock().getLocation().getY();
|
||||
int Z = (int)event.getBlock().getLocation().getZ();
|
||||
String world = event.getBlock().getLocation().getWorld().getName();
|
||||
String sql = "DELETE FROM coreJumpers WHERE X = '"+X+"' AND Y = '"+Y+"' AND Z = '"+Z+"' AND world = '"+world+"'";
|
||||
AnuraCore.getSql().queryUpdate(sql);
|
||||
}
|
||||
else if(event.getBlock().getState() instanceof Sign)
|
||||
{
|
||||
Sign s = (Sign)event.getBlock().getState();
|
||||
Location loc = s.getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
AnuraCore.sql.queryUpdate("DELETE FROM coreWarpSigns WHERE X = '"+X+"' AND Y = '"+Y+"' AND Z = '"+Z+"' AND world = '"+world+"' AND server = '"+server+"'");
|
||||
}
|
||||
else if(event.getBlock().getState().getData() instanceof Stairs)
|
||||
{
|
||||
if(plugin.sittingBlocks.containsValue(event.getBlock()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
44
src/de/anura/core/BlockPlace.java
Normal file
44
src/de/anura/core/BlockPlace.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
|
||||
public class BlockPlace implements Listener
|
||||
{
|
||||
public BlockPlace(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if(plugin.getConfig().getBoolean("no-change-blocks"))
|
||||
{
|
||||
if(!event.getPlayer().hasPermission("core.rules.blocks.place"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if(plugin.flowerPots.containsValue(event.getBlock().getLocation()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Block b = event.getBlock();
|
||||
final int pot = API.getKeyByValue(plugin.flowerPots, b.getLocation());
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
b.setType(Material.BROWN_MUSHROOM);
|
||||
AnuraCore.getInstance().pots.refreshPot(pot);
|
||||
}
|
||||
|
||||
}, 3);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
25
src/de/anura/core/BlockSpread.java
Normal file
25
src/de/anura/core/BlockSpread.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
|
||||
public class BlockSpread implements Listener
|
||||
{
|
||||
public BlockSpread(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockSpread(BlockSpreadEvent event)
|
||||
{
|
||||
if(event.getNewState().getType().equals(Material.BROWN_MUSHROOM) && plugin.getConfig().getBoolean("disable-mushroom-spread"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
34
src/de/anura/core/CmdPreprocess.java
Normal file
34
src/de/anura/core/CmdPreprocess.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CmdPreprocess implements Listener
|
||||
{
|
||||
public CmdPreprocess(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if(event.getMessage().startsWith("/?"))
|
||||
{
|
||||
if(!event.getPlayer().hasPermission("core.commands.help"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
API.statusMsg(event.getPlayer(), "help_command_info", true);
|
||||
}
|
||||
}
|
||||
else if(plugin.disableCommandsAdventure.containsKey(event.getPlayer()) && plugin.disableCommandsAdventure.get(event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
API.statusMsg(event.getPlayer(), "no_command_red_mg", ChatColor.YELLOW);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
25
src/de/anura/core/EntityDamage.java
Normal file
25
src/de/anura/core/EntityDamage.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class EntityDamage implements Listener
|
||||
{
|
||||
public EntityDamage(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if(event.getEntity() instanceof Player && plugin.getConfig().getBoolean("no-damage"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
32
src/de/anura/core/EntityDamageByE.java
Normal file
32
src/de/anura/core/EntityDamageByE.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class EntityDamageByE implements Listener
|
||||
{
|
||||
public EntityDamageByE(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamageByE(EntityDamageByEntityEvent event)
|
||||
{
|
||||
if(event.getEntity() instanceof ItemFrame && plugin.getConfig().getBoolean("no-change-blocks"))
|
||||
{
|
||||
if(event.getDamager() instanceof Player)
|
||||
{
|
||||
if(!((Player)event.getDamager()).hasPermission("core.rules.blocks.break"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
169
src/de/anura/core/Features.java
Normal file
169
src/de/anura/core/Features.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
||||
public class Features implements Listener {
|
||||
|
||||
public enum Feature {
|
||||
DOUBLE_JUMP(1);
|
||||
private Feature(int id) {
|
||||
this.featureId = id;
|
||||
}
|
||||
private final int featureId;
|
||||
private static final HashMap<Integer, Feature> BY_ID = new HashMap<>();
|
||||
public static Feature getById(Integer id)
|
||||
{
|
||||
return BY_ID.get(id);
|
||||
}
|
||||
static {
|
||||
for (Feature feature : values()) {
|
||||
BY_ID.put(feature.featureId, feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Features()
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(this, AnuraCore.getInstance());
|
||||
}
|
||||
|
||||
private final HashMap<Player, ArrayList<Feature>> playerFeatures = new HashMap<>();
|
||||
private final HashMap<Player, Boolean> canDoubleJump = new HashMap<>();
|
||||
|
||||
public void updateFeatures(Player P)
|
||||
{
|
||||
if(!mainLobby()) return;
|
||||
try {
|
||||
ResultSet rs = API.getMySql().querySelect("SELECT featureId FROM coreFeatures WHERE playerId = (SELECT id FROM players WHERE uuid = '"+P.getUniqueId().toString()+"')");
|
||||
resetPlayerFeatures(P);
|
||||
playerFeatures.put(P, new ArrayList<Feature>());
|
||||
while(rs.next())
|
||||
{
|
||||
if(Feature.getById(rs.getInt("featureId")) != null)
|
||||
{
|
||||
this.addFeature(P, Feature.getById(rs.getInt("featureId")));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.err.println("Could not update player features because of a sql exception: "+ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public void updateFeaturesAll()
|
||||
{
|
||||
if(!mainLobby()) return;
|
||||
for(Player P : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
updateFeatures(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
for(Player P : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
this.resetPlayerFeatures(P);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFeature(Player P, Feature f)
|
||||
{
|
||||
if(!mainLobby()) return false;
|
||||
if(playerFeatures.containsKey(P))
|
||||
{
|
||||
return playerFeatures.get(P).contains(f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void resetPlayerFeatures(Player P)
|
||||
{
|
||||
if(!playerFeatures.containsKey(P)) return;
|
||||
for(Feature f : (ArrayList<Feature>)playerFeatures.get(P).clone())
|
||||
{
|
||||
removeFeature(P, f);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFeature(Player P, Feature f)
|
||||
{
|
||||
if(!mainLobby()) return;
|
||||
if(playerFeatures.containsKey(P)) playerFeatures.get(P).remove(f);
|
||||
if(f.equals(Feature.DOUBLE_JUMP))
|
||||
{
|
||||
if(!P.getGameMode().equals(GameMode.CREATIVE))
|
||||
{
|
||||
P.setAllowFlight(false);
|
||||
P.setFoodLevel(20);
|
||||
}
|
||||
this.canDoubleJump.put(P, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void addFeature(Player P, Feature f)
|
||||
{
|
||||
if(!mainLobby()) return;
|
||||
if(playerFeatures.containsKey(P) && !hasFeature(P, f)) playerFeatures.get(P).add(f);
|
||||
if(f.equals(Feature.DOUBLE_JUMP))
|
||||
{
|
||||
P.setAllowFlight(true);
|
||||
this.canDoubleJump.put(P, true);
|
||||
}
|
||||
}
|
||||
private boolean mainLobby()
|
||||
{
|
||||
return AnuraCore.getInstance().getConfig().getBoolean("is-main-lobby");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
if(!mainLobby()) return;
|
||||
Player P = event.getPlayer();
|
||||
if(this.hasFeature(P, Feature.DOUBLE_JUMP))
|
||||
{
|
||||
if(this.canDoubleJump.containsKey(P) && !this.canDoubleJump.get(P) && ((Entity)P).isOnGround())
|
||||
{
|
||||
this.canDoubleJump.put(P, true);
|
||||
P.setFoodLevel(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onToggleFlight(PlayerToggleFlightEvent event)
|
||||
{
|
||||
if(!mainLobby()) return;
|
||||
Player P = event.getPlayer();
|
||||
|
||||
if(this.hasFeature(P, Feature.DOUBLE_JUMP) && !P.getGameMode().equals(GameMode.CREATIVE))
|
||||
{
|
||||
if(this.canDoubleJump.containsKey(P) && this.canDoubleJump.get(P))
|
||||
{
|
||||
this.canDoubleJump.put(P, false);
|
||||
P.setFoodLevel(1);
|
||||
Vector v = P.getLocation().getDirection();
|
||||
P.setVelocity(v.multiply(new Vector(1,2,1)));
|
||||
P.setVelocity(P.getVelocity().setY(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector v = P.getVelocity();
|
||||
P.setVelocity(v.setY(-0.4));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
174
src/de/anura/core/FlowerPots.java
Normal file
174
src/de/anura/core/FlowerPots.java
Normal file
@@ -0,0 +1,174 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class FlowerPots {
|
||||
private final HashMap<Player, HashMap<Integer, Boolean>> foundCache = new HashMap<>();
|
||||
private final HashMap<Player, HashMap<Integer, Integer>> foundTimestamp = new HashMap<>();
|
||||
|
||||
public boolean foundPot(Player P, Integer pot)
|
||||
{
|
||||
if(!foundCache.containsKey(P)) refreshCache(P);
|
||||
if(foundCache.get(P).containsKey(pot))
|
||||
{
|
||||
if(foundCache.get(P).get(pot) && foundTimestamp.get(P).containsKey(pot))
|
||||
{
|
||||
if((System.currentTimeMillis() / 1000 - foundTimestamp.get(P).get(pot)) >= getPotWaitTime(pot))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getPotWaitTime(Integer pot)
|
||||
{
|
||||
if (AnuraCore.getInstance().flowerPots.containsKey(pot))
|
||||
{
|
||||
if (AnuraCore.getInstance().flowerPotsWait.containsKey(pot))
|
||||
{
|
||||
return AnuraCore.getInstance().flowerPotsWait.get(pot);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void refreshCache(Player P)
|
||||
{
|
||||
try {
|
||||
ResultSet rs = AnuraCore.getSql().querySelect("SELECT id, timestamp, type FROM coreFoundPots WHERE player = (SELECT id FROM players WHERE uuid = '"+P.getUniqueId().toString()+"')");
|
||||
HashMap<Integer, Boolean> list = new HashMap<>();
|
||||
HashMap<Integer, Integer> listTimes = new HashMap<>();
|
||||
while(rs.next())
|
||||
{
|
||||
list.put(rs.getInt("id"), rs.getBoolean("type"));
|
||||
if(rs.getBoolean("type"))
|
||||
{
|
||||
listTimes.put(rs.getInt("id"), rs.getInt("timestamp"));
|
||||
}
|
||||
}
|
||||
this.foundCache.put(P, list);
|
||||
this.foundTimestamp.put(P, listTimes);
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("Error refreshCache(FlowerPots)");
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshPot(Integer pot)
|
||||
{
|
||||
Location l = AnuraCore.getInstance().flowerPots.get(pot);
|
||||
for(Player P : l.getWorld().getPlayers())
|
||||
{
|
||||
if(P.getLocation().distance(l) < 20)
|
||||
{
|
||||
refreshPlayerPot(P, pot, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshPlayerPot(Player p, Integer pot, Location l)
|
||||
{
|
||||
if(!this.foundPot(p, pot))
|
||||
{
|
||||
p.sendBlockChange(l, Material.FLOWER_POT, (byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.sendBlockChange(l, Material.AIR, (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshPlayer(Player p)
|
||||
{
|
||||
for(Map.Entry<Integer, Location> pots : AnuraCore.getInstance().flowerPots.entrySet())
|
||||
{
|
||||
if(pots.getValue().getWorld().equals(p.getLocation().getWorld()) && pots.getValue().distance(p.getLocation()) < 20)
|
||||
{
|
||||
refreshPlayerPot(p, pots.getKey(), pots.getValue());
|
||||
}
|
||||
}
|
||||
AnuraCore.getInstance().lastLoc.put(p, p.getLocation());
|
||||
}
|
||||
|
||||
public void playerFoundPot(Player P, Integer pot)
|
||||
{
|
||||
if(!foundPot(P, pot))
|
||||
{
|
||||
Integer time = getPotWaitTime(pot);
|
||||
boolean alreadyFound = foundCache.get(P).containsKey(pot);
|
||||
int type = 0;
|
||||
if(time == -1)
|
||||
{
|
||||
foundCache.get(P).put(pot, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
type = 1;
|
||||
foundCache.get(P).put(pot, true);
|
||||
foundTimestamp.get(P).put(pot, (int)(System.currentTimeMillis() / 1000));
|
||||
}
|
||||
String sql;
|
||||
if(alreadyFound)
|
||||
{
|
||||
sql = "UPDATE coreFoundPots SET timestamp = '"+(System.currentTimeMillis() / 1000)+"', type = 1 WHERE player = (SELECT id FROM players WHERE uuid = '"+P.getUniqueId().toString()+"')";
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = "INSERT INTO coreFoundPots(id, player, timestamp, type) VALUES('"+pot+"', (SELECT id FROM players WHERE uuid = '"+P.getUniqueId().toString()+"'),'"+(int) (System.currentTimeMillis() / 1000)+"','"+type+"')";
|
||||
}
|
||||
AnuraCore.getSql().queryUpdate(sql);
|
||||
Location loc = AnuraCore.getInstance().flowerPots.get(pot);
|
||||
for(int i = 0; i < 20; i++)
|
||||
{
|
||||
loc.getWorld().playEffect(loc, Effect.FIREWORKS_SPARK, 4);
|
||||
}
|
||||
P.playSound(loc, Sound.LEVEL_UP, 1, (float)1.5);
|
||||
ResultSet rs = AnuraCore.getSql().querySelect("SELECT url, name, money FROM corePots WHERE id = '"+pot+"'");
|
||||
try {
|
||||
rs.first();
|
||||
AnuraCore.getSql().queryUpdate("UPDATE players SET money = money + '"+rs.getInt("money")+"' WHERE uuid = '"+P.getUniqueId().toString()+"'");
|
||||
P.sendMessage(ChatColor.RED + "---------- "+ChatColor.YELLOW + "Achievement"+ChatColor.RED+ " ----------");
|
||||
P.sendMessage(ChatColor.BLUE + rs.getString("name"));
|
||||
P.sendMessage("" + ChatColor.GOLD + ChatColor.UNDERLINE + rs.getString("url"));
|
||||
P.sendMessage("");
|
||||
P.sendMessage(ChatColor.RED + "---------- "+ChatColor.YELLOW + "Achievement"+ChatColor.RED+ " ----------");
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("Error playerFoundPot(FlowerPot)");
|
||||
}
|
||||
}
|
||||
else if(getPotWaitTime(pot) != -1 && foundCache.containsKey(P) && foundCache.get(P).containsKey(pot) && foundTimestamp.containsKey(P) && foundTimestamp.get(P).containsKey(pot))
|
||||
{
|
||||
int current = (int)(System.currentTimeMillis() / 1000);
|
||||
int found = foundTimestamp.get(P).get(pot);
|
||||
int waitTime = getPotWaitTime(pot);
|
||||
int toWait = (found + waitTime) - current;
|
||||
if (toWait <= 0) return;
|
||||
String text = ChatColor.RED + API.getl("ach_wait_1", P);
|
||||
if (toWait < 60) {
|
||||
text += " "+ChatColor.GREEN+toWait+" "+ChatColor.RED+API.getl("ach_wait_seconds", P);
|
||||
} else if (toWait < 60*60) {
|
||||
text += " "+ChatColor.GREEN+Math.round(toWait/60)+" "+ChatColor.RED+API.getl("ach_wait_minutes", P);
|
||||
} else if (toWait < 60*60*24) {
|
||||
text += " "+ChatColor.GREEN+Math.round(toWait/60/60)+" "+ChatColor.RED+API.getl("ach_wait_hours", P);
|
||||
} else {
|
||||
text += " "+ChatColor.GREEN+Math.round(toWait/60/60/24)+" "+ChatColor.RED+API.getl("ach_wait_days", P);
|
||||
}
|
||||
text += " "+API.getl("ach_wait_2", P);
|
||||
|
||||
P.sendMessage(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/de/anura/core/FoodChange.java
Normal file
29
src/de/anura/core/FoodChange.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
|
||||
|
||||
public class FoodChange implements Listener
|
||||
{
|
||||
public FoodChange(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onFoodLChange(FoodLevelChangeEvent event)
|
||||
{
|
||||
if(plugin.getConfig().getBoolean("no-hunger"))
|
||||
{
|
||||
if(event.getEntity() instanceof Player)
|
||||
{
|
||||
((Player)event.getEntity()).setFoodLevel(20);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
37
src/de/anura/core/HangingEBreak.java
Normal file
37
src/de/anura/core/HangingEBreak.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
|
||||
|
||||
public class HangingEBreak implements Listener
|
||||
{
|
||||
public HangingEBreak(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onHangingBreakByE(HangingBreakByEntityEvent event)
|
||||
{
|
||||
Player P;
|
||||
if(event.getRemover() instanceof Player)
|
||||
{
|
||||
P = (Player)event.getRemover();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(plugin.getConfig().getBoolean("no-change-blocks"))
|
||||
{
|
||||
if(!P.hasPermission("core.rules.blocks.break"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
21
src/de/anura/core/ImgRenderer.java
Normal file
21
src/de/anura/core/ImgRenderer.java
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.map.MapCanvas;
|
||||
import org.bukkit.map.MapRenderer;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
class ImgRenderer extends MapRenderer {
|
||||
|
||||
private final String name;
|
||||
public ImgRenderer(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MapView mv, MapCanvas mc, Player player) {
|
||||
mc.drawImage(0, 0, AnuraCore.getInstance().renderedImgs.get(this.name));
|
||||
}
|
||||
|
||||
}
|
||||
224
src/de/anura/core/InvClick.java
Normal file
224
src/de/anura/core/InvClick.java
Normal file
@@ -0,0 +1,224 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class InvClick implements Listener
|
||||
{
|
||||
private final AnuraCore plugin;
|
||||
public InvClick(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent event)
|
||||
{
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
Inventory inventory = event.getInventory();
|
||||
if(inventory.getName().equals(AnuraCore.minigamesInvs.get(API.getPlayerLang(player)).getName()) && clicked != null)
|
||||
{
|
||||
if(clicked.getType().equals(Material.BOW))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
try {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF("smash");
|
||||
player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
|
||||
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
else if(clicked.getType().equals(Material.WHEAT))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
plugin.tools.sendStatusMsg(player, "Coming Soon", false);
|
||||
}
|
||||
else if(clicked.getType().equals(Material.FIREWORK))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
plugin.tools.sendStatusMsg(player, "Coming Soon", false);
|
||||
}
|
||||
else if(clicked.getType().equals(Material.ENDER_PEARL))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
player.openInventory(AnuraCore.compassInvs.get(API.getPlayerLang(player)));
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Player p = player;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
}
|
||||
else if(inventory.getName().equals(AnuraCore.compassInvs.get(API.getPlayerLang(player)).getName()) && clicked != null)
|
||||
{
|
||||
if(clicked.getType().equals(Material.RED_ROSE))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
player.openInventory(AnuraCore.lobbyInvs.get(API.getPlayerLang(player)));
|
||||
}
|
||||
|
||||
else if(clicked.getType().equals(Material.CARROT_STICK))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
player.openInventory(AnuraCore.minigamesInvs.get(API.getPlayerLang(player)));
|
||||
}
|
||||
else if(clicked.getType().equals(Material.IRON_PICKAXE))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
API.getTools().sendStatusMsg(player, "Coming Soon", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Player p = player;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
else if(inventory.getName().equals(AnuraCore.lobbyInvs.get(API.getPlayerLang(player)).getName()) && clicked != null)
|
||||
{
|
||||
if(clicked.getType().equals(Material.WATER_BUCKET))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
player.teleport(new Location(Bukkit.getWorld("lobby"), -288, 32, -1714));
|
||||
}
|
||||
else if(clicked.getType().equals(Material.SLIME_BALL))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
plugin.getServer().dispatchCommand(player, "jumpinv");
|
||||
}
|
||||
else if(clicked.getType().equals(Material.WOODEN_DOOR))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
}
|
||||
else if(clicked.getType().equals(Material.ENDER_PEARL))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
player.closeInventory();
|
||||
player.openInventory(AnuraCore.compassInvs.get(API.getPlayerLang(player)));
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Player p = player;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
else if(inventory.getName().equals(plugin.selectLang.getName()) && clicked != null)
|
||||
{
|
||||
if(clicked.getType().equals(Material.BOOK_AND_QUILL))
|
||||
{
|
||||
String language = API.getKeyByValue(plugin.lang.languages, clicked.getItemMeta().getDisplayName().substring(2));
|
||||
event.setCancelled(true);
|
||||
player.closeInventory();
|
||||
API.cachedPlayerLanguage.put(player,language);
|
||||
AnuraCore.sql.queryUpdate("UPDATE players SET lang = '"+language+"' WHERE uuid = '"+player.getUniqueId().toString()+"'");
|
||||
PlayerInventory pi = player.getInventory();
|
||||
if(pi.getItem(0) != null)
|
||||
{
|
||||
pi.setItem(0, plugin.warpCompasses.get(language));
|
||||
}
|
||||
if(pi.getItem(8) != null)
|
||||
{
|
||||
pi.setItem(8, plugin.doors.get(language));
|
||||
}
|
||||
API.statusMsg(player, "lang_changed", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Player p = player;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
else if(!player.hasPermission("core.inventory.interact") && plugin.getConfig().getBoolean("is-main-lobby"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Player p = player;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/de/anura/core/LanguageSupport.java
Normal file
53
src/de/anura/core/LanguageSupport.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class LanguageSupport
|
||||
{
|
||||
private final AnuraCore plugin;
|
||||
public HashMap<String, String> languages = new HashMap<>();
|
||||
private HashMap<String, HashMap<String, String>> languageValues = new HashMap<>();
|
||||
|
||||
public LanguageSupport(AnuraCore plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
ResultSet al = AnuraCore.sql.querySelect("SELECT name, short_name FROM coreAvailableLanguages");
|
||||
try {
|
||||
if(!al.next()) return;
|
||||
al.beforeFirst();
|
||||
String languageString = "";
|
||||
while(al.next())
|
||||
{
|
||||
languages.put(al.getString("short_name"), al.getString("name"));
|
||||
languageString += ", "+al.getString("short_name");
|
||||
languageValues.put(al.getString("short_name"), new HashMap<String, String>());
|
||||
}
|
||||
ResultSet lv = AnuraCore.sql.querySelect("SELECT id"+languageString+" FROM coreLanguages");
|
||||
while(lv.next())
|
||||
{
|
||||
for(String lang : languages.keySet())
|
||||
{
|
||||
languageValues.get(lang).put(lv.getString("id"), lv.getString(lang));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("Language data could not be loaded: "+ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public String get(String id, String lang)
|
||||
{
|
||||
String value;
|
||||
if(languageValues.get(lang).containsKey(id))
|
||||
{
|
||||
value = languageValues.get(lang).get(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = id;
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', value);
|
||||
}
|
||||
}
|
||||
32
src/de/anura/core/LeavesDecay.java
Normal file
32
src/de/anura/core/LeavesDecay.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
|
||||
public class LeavesDecay implements Listener
|
||||
{
|
||||
public LeavesDecay(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeavesDecay(LeavesDecayEvent event)
|
||||
{
|
||||
if(!plugin.getConfig().getBoolean("enable-leaves-decay"))
|
||||
{
|
||||
Block b = event.getBlock();
|
||||
byte data = b.getData();
|
||||
if((data & 0x4) == 0)
|
||||
{
|
||||
data = (byte) (data | 0x4);
|
||||
}
|
||||
b.setData(data);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
204
src/de/anura/core/MySQL.java
Normal file
204
src/de/anura/core/MySQL.java
Normal file
@@ -0,0 +1,204 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class MySQL {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final String username;
|
||||
private final String pw;
|
||||
private final String db;
|
||||
private Connection conn;
|
||||
public FileConfiguration config;
|
||||
private final AnuraCore plugin;
|
||||
public boolean isValid = true;
|
||||
private boolean reconnecting = false;
|
||||
public MySQL(AnuraCore plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
File file = new File("plugins/Core/","database.yml");
|
||||
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
String dbLoc = "database.";
|
||||
cfg.addDefault(dbLoc+"host","localhost");
|
||||
cfg.addDefault(dbLoc+"port",3306);
|
||||
cfg.addDefault(dbLoc+"username","username");
|
||||
cfg.addDefault(dbLoc+"pw","pw");
|
||||
cfg.addDefault(dbLoc+"db","db");
|
||||
cfg.options().copyDefaults(true);
|
||||
try
|
||||
{
|
||||
cfg.save(file);
|
||||
}
|
||||
catch(IOException e)
|
||||
{}
|
||||
this.host = cfg.getString(dbLoc+"host");
|
||||
this.port = cfg.getInt(dbLoc+"port");
|
||||
this.username = cfg.getString(dbLoc+"username");
|
||||
this.pw = cfg.getString(dbLoc+"pw");
|
||||
this.db = cfg.getString(dbLoc+"db");
|
||||
if(!this.openConnection())
|
||||
{
|
||||
Bukkit.broadcastMessage(ChatColor.RED + "No database connection available, please contact a server administrator!");
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.config = cfg;
|
||||
}
|
||||
public String escapeString(String text)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
private Boolean openConnection() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
Connection connLoc = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.db, this.username, this.pw);
|
||||
this.conn = connLoc;
|
||||
return true;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private boolean hasConnection() {
|
||||
try {
|
||||
Boolean validConn = true;
|
||||
if(this.conn == null) validConn = false;
|
||||
else if(!this.conn.isValid(1)) validConn = false;
|
||||
return validConn;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private Boolean reconnect()
|
||||
{
|
||||
if(this.reconnecting)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.reconnecting = true;
|
||||
System.out.println("Reconnecting...");
|
||||
Bukkit.broadcastMessage(ChatColor.YELLOW + "Bitte warten... Plugin-Daten werden geladen...");
|
||||
this.closeConnection();
|
||||
if(!this.openConnection())
|
||||
{
|
||||
Bukkit.broadcastMessage(ChatColor.RED + "Database reconnect failed! Please contact a server administrator!");
|
||||
}
|
||||
else System.out.println("Database reconnect successful!");
|
||||
this.reconnecting = false;
|
||||
return true;
|
||||
}
|
||||
private void queryRedo(final String query, final String type)
|
||||
{
|
||||
if(!this.reconnect())
|
||||
{
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch (type) {
|
||||
case "update":
|
||||
AnuraCore.sql.queryUpdate(query);
|
||||
break;
|
||||
case "select":
|
||||
AnuraCore.sql.querySelect(query);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, 4);
|
||||
}
|
||||
}
|
||||
public void queryUpdate(String query)
|
||||
{
|
||||
if(!this.hasConnection())
|
||||
{
|
||||
queryRedo(query, "update");
|
||||
}
|
||||
Connection connLoc = this.conn;
|
||||
PreparedStatement st = null;
|
||||
try {
|
||||
st = connLoc.prepareStatement(query);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Failed to send Update '" +query+"'! ("+e.getLocalizedMessage()+")");
|
||||
}
|
||||
this.closeRessources(null, st);
|
||||
}
|
||||
public ResultSet querySelect(final String query)
|
||||
{
|
||||
if(!this.hasConnection())
|
||||
{
|
||||
queryRedo(query, "select");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
PreparedStatement st = this.conn.prepareStatement(query);
|
||||
ResultSet returns = this.querySelect(st);
|
||||
if(returns == null)
|
||||
{
|
||||
queryRedo(query, "select");
|
||||
}
|
||||
else
|
||||
{
|
||||
return returns;
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
System.err.println("Unknown error whilst trying to build Prepared Statement!");
|
||||
queryRedo(query, "select");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private ResultSet querySelect(PreparedStatement st)
|
||||
{
|
||||
if(!this.hasConnection())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ResultSet rs;
|
||||
try {
|
||||
rs = st.executeQuery();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
System.err.println("Failed to send 'SELECT'-Query!("+st.toString()+") Will try to reconnect to database just in case... you know...");
|
||||
System.err.println("Caused by: "+e.getMessage());
|
||||
return null;
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
private void closeRessources(ResultSet rs, PreparedStatement st) {
|
||||
if(rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
}
|
||||
if(st != null) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public void closeConnection() {
|
||||
try {
|
||||
if(this.conn != null) this.conn.close();
|
||||
} catch (SQLException e) {}
|
||||
finally
|
||||
{
|
||||
this.conn = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
257
src/de/anura/core/ParticleEffect.java
Normal file
257
src/de/anura/core/ParticleEffect.java
Normal file
@@ -0,0 +1,257 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.ReflectionUtil.DynamicPackage;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* ParticleEffect Library v1.3
|
||||
*
|
||||
* This library was created by @DarkBlade12 based on content related to particles of @microgeek (names and packet values), it allows you to display all Minecraft particle effects on a Bukkit server
|
||||
*
|
||||
* You are welcome to use it, modify it and redistribute it under the following conditions:
|
||||
* 1. Don't claim this class as your own
|
||||
* 2. Don't remove this text
|
||||
*
|
||||
* (Would be nice if you provide credit to me)
|
||||
*
|
||||
* @author DarkBlade12
|
||||
*/
|
||||
public enum ParticleEffect {
|
||||
HUGE_EXPLOSION("hugeexplosion", 0),
|
||||
LARGE_EXPLODE("largeexplode", 1),
|
||||
FIREWORKS_SPARK("fireworksSpark", 2),
|
||||
BUBBLE("bubble", 3),
|
||||
SUSPEND("suspend", 4),
|
||||
DEPTH_SUSPEND("depthSuspend", 5),
|
||||
TOWN_AURA("townaura", 6),
|
||||
CRIT("crit", 7),
|
||||
MAGIC_CRIT("magicCrit", 8),
|
||||
MOB_SPELL("mobSpell", 9),
|
||||
MOB_SPELL_AMBIENT("mobSpellAmbient", 10),
|
||||
SPELL("spell", 11),
|
||||
INSTANT_SPELL("instantSpell", 12),
|
||||
WITCH_MAGIC("witchMagic", 13),
|
||||
NOTE("note", 14),
|
||||
PORTAL("portal", 15),
|
||||
ENCHANTMENT_TABLE("enchantmenttable", 16),
|
||||
EXPLODE("explode", 17),
|
||||
FLAME("flame", 18),
|
||||
LAVA("lava", 19),
|
||||
FOOTSTEP("footstep", 20),
|
||||
SPLASH("splash", 21),
|
||||
LARGE_SMOKE("largesmoke", 22),
|
||||
CLOUD("cloud", 23),
|
||||
RED_DUST("reddust", 24),
|
||||
SNOWBALL_POOF("snowballpoof", 25),
|
||||
DRIP_WATER("dripWater", 26),
|
||||
DRIP_LAVA("dripLava", 27),
|
||||
SNOW_SHOVEL("snowshovel", 28),
|
||||
SLIME("slime", 29),
|
||||
HEART("heart", 30),
|
||||
ANGRY_VILLAGER("angryVillager", 31),
|
||||
HAPPY_VILLAGER("happyVillager", 32);
|
||||
|
||||
private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<>();
|
||||
private static final Map<Integer, ParticleEffect> ID_MAP = new HashMap<>();
|
||||
private static final double MAX_RANGE = 20.0D;
|
||||
private static Constructor<?> PARTICLE_PACKET_CONSTRUCTOR;
|
||||
|
||||
static {
|
||||
for (ParticleEffect effect : values()) {
|
||||
NAME_MAP.put(effect.name, effect);
|
||||
ID_MAP.put(effect.id, effect);
|
||||
}
|
||||
try {
|
||||
PARTICLE_PACKET_CONSTRUCTOR = ReflectionUtil.getConstructor(ReflectionUtil.getClass("PacketPlayOutWorldParticles", DynamicPackage.MINECRAFT_SERVER), String.class, float.class, float.class,
|
||||
float.class, float.class, float.class, float.class, float.class, int.class);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
private String name;
|
||||
private int id;
|
||||
|
||||
ParticleEffect(String name, int id) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static ParticleEffect fromName(String name) {
|
||||
if (name != null)
|
||||
for (Entry<String, ParticleEffect> e : NAME_MAP.entrySet())
|
||||
if (e.getKey().equalsIgnoreCase(name))
|
||||
return e.getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ParticleEffect fromId(int id) {
|
||||
return ID_MAP.get(id);
|
||||
}
|
||||
|
||||
private static List<Player> getPlayersInRange(Location loc, double range) {
|
||||
List<Player> players = new ArrayList<>();
|
||||
double sqr = range * range;
|
||||
for (Player p : loc.getWorld().getPlayers())
|
||||
if (p.getLocation().distanceSquared(loc) <= sqr)
|
||||
players.add(p);
|
||||
return players;
|
||||
}
|
||||
|
||||
private static Object createPacket(String name, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
if (amount <= 0)
|
||||
throw new IllegalArgumentException("Amount of particles has to be greater than 0");
|
||||
try {
|
||||
Object p = PARTICLE_PACKET_CONSTRUCTOR.newInstance(name, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), offsetX, offsetY, offsetZ, speed, amount);
|
||||
return p;
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException e) {
|
||||
Bukkit.getLogger().warning("[ParticleEffect] Failed to create a particle packet!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object createPacket(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
return createPacket(this.getName(), loc, offsetX, offsetY, offsetZ, speed, amount);
|
||||
}
|
||||
|
||||
private static Object createIconCrackPacket(int id, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
return createPacket("iconcrack_" + id, loc, offsetX, offsetY, offsetZ, speed, amount);
|
||||
}
|
||||
|
||||
private static Object createBlockCrackPacket(int id, byte data, Location loc, float offsetX, float offsetY, float offsetZ, int amount) {
|
||||
return createPacket("blockcrack_" + id + "_" + data, loc, offsetX, offsetY, offsetZ, 1.0F, amount);
|
||||
}
|
||||
|
||||
private static Object createBlockDustPacket(int id, byte data, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
return createPacket("blockdust_" + id + "_" + data, loc, offsetX, offsetY, offsetZ, speed, amount);
|
||||
}
|
||||
|
||||
private static void sendPacket(Player p, Object packet) {
|
||||
if (packet != null)
|
||||
try {
|
||||
Object entityPlayer = ReflectionUtil.invokeMethod("getHandle", p.getClass(), p);
|
||||
Object playerConnection = ReflectionUtil.getValue("playerConnection", entityPlayer);
|
||||
ReflectionUtil.invokeMethod("sendPacket", playerConnection.getClass(), playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "[ParticleEffect] Failed to send a particle packet to {0}!", p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendPacket(Collection<Player> players, Object packet) {
|
||||
for (Player p : players)
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a particle effect which is only visible for specific players
|
||||
*/
|
||||
public void display(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
|
||||
sendPacket(Arrays.asList(players), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a particle effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
|
||||
*/
|
||||
public void display(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
display(loc, MAX_RANGE, offsetX, offsetY, offsetZ, speed, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a particle effect which is visible for all players whitin a certain range in the the world of @param loc
|
||||
*/
|
||||
public void display(Location loc, double range, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
if (range > MAX_RANGE)
|
||||
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
|
||||
sendPacket(getPlayersInRange(loc, range), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an icon crack (item break) effect which is only visible for specific players
|
||||
*/
|
||||
public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
|
||||
sendPacket(Arrays.asList(players), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an icon crack (item break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
|
||||
*/
|
||||
public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
displayIconCrack(loc, MAX_RANGE, id, offsetX, offsetY, offsetZ, speed, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an icon crack (item break) effect which is visible for all players whitin a certain range in the the world of @param loc
|
||||
*/
|
||||
public static void displayIconCrack(Location loc, double range, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
if (range > MAX_RANGE)
|
||||
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
|
||||
sendPacket(getPlayersInRange(loc, range), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a block crack (block break) effect which is only visible for specific players
|
||||
*/
|
||||
public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, int amount, Player... players) {
|
||||
sendPacket(Arrays.asList(players), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a block crack (block break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
|
||||
*/
|
||||
public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, int amount) {
|
||||
displayBlockCrack(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a block crack (block break) effect which is visible for all players whitin a certain range in the the world of @param loc
|
||||
*/
|
||||
public static void displayBlockCrack(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, int amount) {
|
||||
if (range > MAX_RANGE)
|
||||
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
|
||||
sendPacket(getPlayersInRange(loc, range), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a block dust effect which is only visible for specific players
|
||||
*/
|
||||
public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
|
||||
sendPacket(Arrays.asList(players), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a block dust effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
|
||||
*/
|
||||
public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
displayBlockDust(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a block dust effect which is visible for all players whitin a certain range in the the world of @param loc
|
||||
*/
|
||||
public static void displayBlockDust(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
|
||||
if (range > MAX_RANGE)
|
||||
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
|
||||
sendPacket(getPlayersInRange(loc, range), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
|
||||
}
|
||||
}
|
||||
216
src/de/anura/core/Permissions.java
Normal file
216
src/de/anura/core/Permissions.java
Normal file
@@ -0,0 +1,216 @@
|
||||
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
public final class Permissions implements Listener {
|
||||
|
||||
private final HashMap<Integer, String> groupNames = new HashMap<>();
|
||||
private final HashMap<Integer, ArrayList<String>> groupPerms = new HashMap<>();
|
||||
private final HashMap<UUID, ArrayList<Integer>> playerGroups = new HashMap<>();
|
||||
private final HashMap<Integer, Integer> groupParents = new HashMap<>();
|
||||
private final HashMap<Integer, String> groupPrefix = new HashMap<>();
|
||||
private final HashMap<Integer, String> groupSuffix = new HashMap<>();
|
||||
private final HashMap<Integer, String> groupListColor = new HashMap<>();
|
||||
private final HashMap<Player, PermissionAttachment> permAttachments = new HashMap<>();
|
||||
|
||||
private int groupAutoIncrement = 0;
|
||||
private final AnuraCore plugin;
|
||||
|
||||
public Permissions(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.reload();
|
||||
this.plugin = plugin;
|
||||
this.createPermAttachs();
|
||||
this.updateAllPlayers();
|
||||
}
|
||||
|
||||
//Event handlers
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player P = event.getPlayer();
|
||||
this.permAttachments.put(P, P.addAttachment(this.plugin));
|
||||
this.updatePlayer(P);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerKick(PlayerKickEvent event)
|
||||
{
|
||||
Player P = event.getPlayer();
|
||||
if(this.permAttachments.get(P) == null) return;
|
||||
P.removeAttachment(this.permAttachments.get(P));
|
||||
this.permAttachments.remove(P);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
Player P = event.getPlayer();
|
||||
if(this.permAttachments.get(P) == null) return;
|
||||
P.removeAttachment(this.permAttachments.get(P));
|
||||
this.permAttachments.remove(P);
|
||||
}
|
||||
|
||||
//The permission stuff
|
||||
private void createPermAttachs()
|
||||
{
|
||||
for(Player P : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
this.permAttachments.put(P, P.addAttachment(this.plugin));
|
||||
}
|
||||
}
|
||||
public void updateAllPlayers()
|
||||
{
|
||||
for(Player P : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
this.updatePlayer(P);
|
||||
}
|
||||
}
|
||||
public void updatePlayer(Player P)
|
||||
{
|
||||
PermissionAttachment pa = this.permAttachments.get(P);
|
||||
for(String p : pa.getPermissions().keySet())
|
||||
{
|
||||
pa.unsetPermission(p);
|
||||
}
|
||||
if(!this.playerGroups.containsKey(P.getUniqueId()))
|
||||
{
|
||||
this.playerGroups.put(P.getUniqueId(), new ArrayList<Integer>());
|
||||
}
|
||||
ArrayList<Integer> groups = this.playerGroups.get(P.getUniqueId());
|
||||
ArrayList<Integer> assignedGroups = new ArrayList<>();
|
||||
String prefixes = "";
|
||||
String suffixes = "";
|
||||
String listColor = "";
|
||||
for(Integer g : groups)
|
||||
{
|
||||
if(assignedGroups.contains(g)) continue;
|
||||
assignedGroups.add(g);
|
||||
for(String perm : this.groupPerms.get(g))
|
||||
{
|
||||
pa.setPermission(perm, true);
|
||||
}
|
||||
ArrayList<String> perms = this.getParentPerms(g, assignedGroups);
|
||||
for(String perm : perms)
|
||||
{
|
||||
pa.setPermission(perm, true);
|
||||
}
|
||||
if(this.groupPrefix.containsKey(g)) prefixes += this.groupPrefix.get(g);
|
||||
if(this.groupSuffix.containsKey(g)) suffixes += this.groupSuffix.get(g);
|
||||
if(this.groupListColor.containsKey(g)) listColor = this.groupListColor.get(g);
|
||||
}
|
||||
String name = prefixes + P.getName() + suffixes;
|
||||
P.setDisplayName(name);
|
||||
P.setPlayerListName(listColor + P.getName());
|
||||
}
|
||||
private ArrayList<String> getParentPerms(Integer group, ArrayList<Integer> assigned)
|
||||
{
|
||||
ArrayList<String> toReturn = new ArrayList<>();
|
||||
if(this.groupParents.get(group) == -1)
|
||||
{
|
||||
return toReturn;
|
||||
}
|
||||
if(assigned.contains(this.groupParents.get(group)))
|
||||
{
|
||||
return toReturn;
|
||||
}
|
||||
for(String perm : this.groupPerms.get(this.groupParents.get(group)))
|
||||
{
|
||||
toReturn.add(perm);
|
||||
}
|
||||
for(String perm : this.getParentPerms(this.groupParents.get(group), assigned))
|
||||
{
|
||||
toReturn.add(perm);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
public String reload()
|
||||
{
|
||||
ResultSet groupsRs = AnuraCore.sql.querySelect("SELECT prefix, suffix, parent, name, id, listColor FROM permGroups");
|
||||
ResultSet permsRs = AnuraCore.sql.querySelect("SELECT `group`, name FROM permPerms");
|
||||
ResultSet userRs = AnuraCore.sql.querySelect("SELECT playerUUID, `group` FROM permPlayerGroups");
|
||||
this.groupNames.clear();
|
||||
this.groupPerms.clear();
|
||||
this.playerGroups.clear();
|
||||
this.groupParents.clear();
|
||||
this.groupPrefix.clear();
|
||||
this.groupSuffix.clear();
|
||||
HashMap<Integer, Integer> groupIds = new HashMap<>();
|
||||
this.groupAutoIncrement = 0;
|
||||
try {
|
||||
groupsRs.last();
|
||||
if(groupsRs.getRow() != 0)
|
||||
{
|
||||
groupsRs.beforeFirst();
|
||||
while(groupsRs.next())
|
||||
{
|
||||
int id = this.groupAutoIncrement;
|
||||
this.groupNames.put(id, groupsRs.getString("name"));
|
||||
this.groupPerms.put(id, new ArrayList<String>());
|
||||
this.groupParents.put(id, groupsRs.getInt("parent"));
|
||||
if(groupsRs.getString("prefix") != null) this.groupPrefix.put(id, groupsRs.getString("prefix"));
|
||||
if(groupsRs.getString("suffix") != null) this.groupSuffix.put(id, groupsRs.getString("suffix"));
|
||||
if(groupsRs.getString("listColor") != null) this.groupListColor.put(id, groupsRs.getString("listColor"));
|
||||
groupIds.put(groupsRs.getInt("id"), id);
|
||||
this.groupAutoIncrement++;
|
||||
}
|
||||
}
|
||||
permsRs.last();
|
||||
if(permsRs.getRow() != 0)
|
||||
{
|
||||
permsRs.beforeFirst();
|
||||
while(permsRs.next())
|
||||
{
|
||||
int groupId = groupIds.get(permsRs.getInt("group"));
|
||||
if(this.groupNames.containsKey(groupId))
|
||||
{
|
||||
|
||||
this.groupPerms.get(groupId).add(permsRs.getString("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
userRs.last();
|
||||
if(userRs.getRow() != 0)
|
||||
{
|
||||
userRs.beforeFirst();
|
||||
while(userRs.next())
|
||||
{
|
||||
int groupId = groupIds.get(userRs.getInt("group"));
|
||||
if(this.groupNames.containsKey(groupId))
|
||||
{
|
||||
ArrayList<Integer> groupList = this.playerGroups.get(UUID.fromString(userRs.getString("playerUUID")));
|
||||
if(groupList == null)
|
||||
{
|
||||
groupList = new ArrayList<>();
|
||||
}
|
||||
groupList.add(groupId);
|
||||
this.playerGroups.put(UUID.fromString(userRs.getString("playerUUID")), groupList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.err.println("Was not able to load permissions. Sorry. ("+ex.getLocalizedMessage()+")");
|
||||
}
|
||||
return ChatColor.GREEN + "Permissions reloaded!";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
25
src/de/anura/core/PlayerChat.java
Normal file
25
src/de/anura/core/PlayerChat.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class PlayerChat implements Listener
|
||||
{
|
||||
public PlayerChat(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
if(event.isAsynchronous())
|
||||
{
|
||||
event.setFormat(event.getPlayer().getDisplayName() + ChatColor.GRAY + ":" + ChatColor.WHITE + " " + event.getMessage());
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
261
src/de/anura/core/PlayerInteract.java
Normal file
261
src/de/anura/core/PlayerInteract.java
Normal file
@@ -0,0 +1,261 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PlayerInteract implements Listener
|
||||
{
|
||||
public PlayerInteract(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
final Block block = event.getClickedBlock();
|
||||
if(plugin.selectableJumper.containsKey(event.getPlayer()))
|
||||
{
|
||||
if(event.getPlayer().hasPermission("core.commands.setjumper"))
|
||||
{
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_BLOCK))
|
||||
{
|
||||
String type;
|
||||
if(event.getClickedBlock().getType().equals(Material.ENDER_CHEST))
|
||||
{
|
||||
type = "high";
|
||||
}
|
||||
else if(event.getClickedBlock().getType().equals(Material.RAILS))
|
||||
{
|
||||
type = "far";
|
||||
}
|
||||
else
|
||||
{
|
||||
API.statusMsg(event.getPlayer(), "setjumper_block_not_supported", false);
|
||||
plugin.selectableJumper.remove(event.getPlayer());
|
||||
return;
|
||||
}
|
||||
Double X = event.getClickedBlock().getLocation().getX();
|
||||
Double Y = event.getClickedBlock().getLocation().getY();
|
||||
Double Z = event.getClickedBlock().getLocation().getZ();
|
||||
String world = event.getClickedBlock().getLocation().getWorld().getName();
|
||||
String sql = "INSERT INTO coreJumpers(X,Y,Z,world,height,type) VALUES('"+X+"','"+Y+"','"+Z+"','"+world+"','"+plugin.selectableJumper.get(event.getPlayer())+"','"+type+"')";
|
||||
AnuraCore.getSql().queryUpdate(sql);
|
||||
plugin.selectableJumper.remove(event.getPlayer());
|
||||
API.statusMsg(event.getPlayer(), "setjumper_done", true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(block != null)
|
||||
{
|
||||
if(block.getState() instanceof Sign && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
{
|
||||
Sign sign = (Sign)block.getState();
|
||||
Location loc = sign.getLocation();
|
||||
Player P = event.getPlayer();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
ResultSet rs = AnuraCore.sql.querySelect("SELECT type, value FROM coreWarpSigns WHERE X = '"+X+"' AND Y = '"+Y+"' AND Z = '"+Z+"' AND world = '"+world+"' AND server = '"+server+"'");
|
||||
try {
|
||||
rs.last();
|
||||
if(rs.getRow() != 0)
|
||||
{
|
||||
rs.first();
|
||||
if(rs.getString("type").equalsIgnoreCase("warp"))
|
||||
{
|
||||
String warp = rs.getString("value");
|
||||
ResultSet rs2 = AnuraCore.sql.querySelect("SELECT world, X, Y, Z FROM coreWarps WHERE name = '"+warp+"' AND server = '"+plugin.getConfig().getString("server-name")+"'");
|
||||
rs2.last();
|
||||
if(rs2.getRow() == 0)
|
||||
{
|
||||
API.statusMsg(P, "warpsign_warp_not_exist", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(plugin.getServer().getWorld(rs2.getString("world")) != null)
|
||||
{
|
||||
Location target = new Location(plugin.getServer().getWorld(rs2.getString("world")), rs2.getInt("X"), rs2.getInt("Y"), rs2.getInt("Z"));
|
||||
P.teleport(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(rs.getString("type").equalsIgnoreCase("spawn"))
|
||||
{
|
||||
P.teleport(loc.getWorld().getSpawnLocation());
|
||||
}
|
||||
else if(rs.getString("type").equalsIgnoreCase("server"))
|
||||
{
|
||||
String targetServer = rs.getString("value");
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(targetServer);
|
||||
P.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("SQLException in playerInteract: "+ex.getLocalizedMessage());
|
||||
} catch (IOException ex) {
|
||||
System.out.println("IOException in playerInteract: "+ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if(block.getState().getData() instanceof Stairs)
|
||||
{
|
||||
if(plugin.stairMode.contains(event.getPlayer()) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if(plugin.sittableBlocks.contains(block))
|
||||
{
|
||||
plugin.sittableBlocks.remove(block);
|
||||
API.getTools().sendStatusMsg(event.getPlayer(), "Removed!", false);
|
||||
int X = block.getLocation().getBlockX();
|
||||
int Y = block.getLocation().getBlockY();
|
||||
int Z = block.getLocation().getBlockZ();
|
||||
API.getMySql().queryUpdate("DELETE FROM coreStairs WHERE server = '"+plugin.getConfig().getString("server-name")+"' AND world = '"+block.getWorld().getName()+"' AND X = '"+X+"' AND Y = '"+Y+"' AND Z = '"+Z+"'");
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.sittableBlocks.add(block);
|
||||
API.getTools().sendStatusMsg(event.getPlayer(), "Added!", true);
|
||||
int X = block.getLocation().getBlockX();
|
||||
int Y = block.getLocation().getBlockY();
|
||||
int Z = block.getLocation().getBlockZ();
|
||||
API.getMySql().queryUpdate("INSERT INTO coreStairs(server,world,X,Y,Z) VALUES('"+plugin.getConfig().getString("server-name")+"','"+block.getWorld().getName()+"','"+X+"','"+Y+"','"+Z+"')");
|
||||
}
|
||||
}
|
||||
else if(plugin.getConfig().getBoolean("allow-stairs-sit") && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && plugin.sittableBlocks.contains(block))
|
||||
{
|
||||
if(plugin.sittingPlayer.containsKey(event.getPlayer()))
|
||||
{
|
||||
API.statusMsg(event.getPlayer(), "sitting_already", false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if(plugin.sittingBlocks.containsValue(block))
|
||||
{
|
||||
API.statusMsg(event.getPlayer(), "sitting_occupied", false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stairs s = (Stairs)block.getState().getData();
|
||||
if(!s.isInverted())
|
||||
{
|
||||
Location loc = block.getLocation();
|
||||
loc = loc.add(0.5, 0.05, 0.5);
|
||||
loc.add(s.getFacing().getModX()*0.2, 0, s.getFacing().getModZ()*0.2);
|
||||
Arrow a = loc.getWorld().spawnArrow(loc, new Vector(0,0,0), 0, 0);
|
||||
a.setPassenger(event.getPlayer());
|
||||
plugin.sittingPlayer.put(event.getPlayer(), a);
|
||||
plugin.sittingBlocks.put(event.getPlayer(), block);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(plugin.flowerPots.containsValue(block.getLocation()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
final Player p = event.getPlayer();
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
p.sendBlockChange(block.getLocation(), Material.AIR, (byte)0);
|
||||
}
|
||||
|
||||
}, 3);
|
||||
plugin.pots.playerFoundPot(event.getPlayer(), API.getKeyByValue(plugin.flowerPots, block.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
if(event.hasItem())
|
||||
{
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
{
|
||||
if(event.getItem().equals(plugin.warpCompasses.get(API.getPlayerLang(event.getPlayer()))))
|
||||
{
|
||||
plugin.openGameSelectWindow(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
final Player p = event.getPlayer();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
else if(event.getItem().equals(plugin.doors.get(API.getPlayerLang(event.getPlayer()))))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Player player = event.getPlayer();
|
||||
player.teleport(player.getLocation().getWorld().getSpawnLocation());
|
||||
final Player p = event.getPlayer();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
else if(event.getItem().equals(plugin.selLang))
|
||||
{
|
||||
event.getPlayer().openInventory(plugin.selectLang);
|
||||
event.setCancelled(true);
|
||||
final Player p = event.getPlayer();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
p.updateInventory();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(plugin.getConfig().getBoolean("no-change-blocks"))
|
||||
{
|
||||
if(!event.getPlayer().hasPermission("core.rules.blocks.interact"))
|
||||
{
|
||||
Boolean cancelled = true;
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
{
|
||||
if(event.getClickedBlock().getType().equals(Material.STONE_BUTTON)) cancelled = false;
|
||||
else if(event.getClickedBlock().getType().equals(Material.WOOD_BUTTON)) cancelled = false;
|
||||
}
|
||||
else if(event.getAction().equals(Action.PHYSICAL)) cancelled = false;
|
||||
else if(event.getAction().equals(Action.RIGHT_CLICK_AIR))
|
||||
{
|
||||
if(event.getPlayer().getItemInHand().getType().equals(Material.BOW)) cancelled = false;
|
||||
else if(event.getPlayer().getItemInHand().getType().equals(Material.EXP_BOTTLE)) cancelled = false;
|
||||
}
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
60
src/de/anura/core/PlayerInteractE.java
Normal file
60
src/de/anura/core/PlayerInteractE.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class PlayerInteractE implements Listener
|
||||
{
|
||||
public PlayerInteractE(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractE(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if(event.getRightClicked().getType().equals(EntityType.ITEM_FRAME) && plugin.getConfig().getBoolean("no-change-blocks"))
|
||||
{
|
||||
if(!event.getPlayer().hasPermission("core.rules.blocks.interact"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else if(event.getRightClicked().getType().equals(EntityType.CHICKEN) && plugin.getConfig().getBoolean("golf"))
|
||||
{
|
||||
Player P = event.getPlayer();
|
||||
// Item i = (Item)event.getRightClicked();
|
||||
Chicken b = (Chicken)event.getRightClicked();
|
||||
if(P.getItemInHand().getType().equals(Material.STICK))
|
||||
{
|
||||
int power;
|
||||
|
||||
if(!plugin.golfPower.containsKey(P))
|
||||
{
|
||||
power = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
power = plugin.golfPower.get(P);
|
||||
power++;
|
||||
}
|
||||
if(power > 40)
|
||||
{
|
||||
power = 40;
|
||||
}
|
||||
System.out.println(power);
|
||||
plugin.golfPower.put(P, power);
|
||||
plugin.releaseGolf.put(P, false);
|
||||
plugin.golfBall.put(P, b);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
65
src/de/anura/core/PlayerJoin.java
Normal file
65
src/de/anura/core/PlayerJoin.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
|
||||
public class PlayerJoin implements Listener
|
||||
{
|
||||
public PlayerJoin(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
ResultSet rs;
|
||||
try {
|
||||
rs = AnuraCore.getSql().querySelect("SELECT name FROM players WHERE uuid LIKE '"+uuid.toString()+"'");
|
||||
if(rs==null) {
|
||||
event.getPlayer().kickPlayer("Please try again");
|
||||
event.setJoinMessage(null);
|
||||
return;
|
||||
}
|
||||
rs.last();
|
||||
if(rs.getRow() != 1)
|
||||
{
|
||||
AnuraCore.getSql().queryUpdate("INSERT INTO players(`uuid`,`game`,`waiting`,`gameName`) VALUES('"+uuid.toString()+"','none','none','')");
|
||||
}
|
||||
}
|
||||
catch(SQLException e) {
|
||||
}
|
||||
event.setJoinMessage(null);
|
||||
if(plugin.getConfig().getBoolean("is-main-lobby"))
|
||||
{
|
||||
PlayerInventory pi = event.getPlayer().getInventory();
|
||||
pi.clear();
|
||||
pi.setHeldItemSlot(0);
|
||||
pi.setItemInHand(plugin.warpCompasses.get(API.getPlayerLang(event.getPlayer())));
|
||||
pi.setHeldItemSlot(8);
|
||||
pi.setItemInHand(plugin.doors.get(API.getPlayerLang(event.getPlayer())));
|
||||
pi.setHeldItemSlot(1);
|
||||
pi.setItemInHand(plugin.selLang);
|
||||
pi.setHeldItemSlot(0);
|
||||
}
|
||||
plugin.pots.refreshCache(event.getPlayer());
|
||||
plugin.pots.refreshPlayer(event.getPlayer());
|
||||
plugin.getFeatures().updateFeatures(event.getPlayer());
|
||||
plugin.disableCommandsAdventure.put(event.getPlayer(), false);
|
||||
if(plugin.getConfig().getBoolean("on-join-to-spawn"))
|
||||
{
|
||||
event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation());
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
38
src/de/anura/core/PlayerKick.java
Normal file
38
src/de/anura/core/PlayerKick.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
|
||||
public class PlayerKick implements Listener
|
||||
{
|
||||
public PlayerKick(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerKick(PlayerKickEvent event)
|
||||
{
|
||||
AnuraCore.getInstance().disableCommandsAdventure.remove(event.getPlayer());
|
||||
if(!plugin.getConfig().getBoolean("is-main-lobby"))
|
||||
{
|
||||
try {
|
||||
plugin.endSitting(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF("lobby");
|
||||
event.getPlayer().sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
|
||||
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
event.setLeaveMessage(null);
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
143
src/de/anura/core/PlayerMove.java
Normal file
143
src/de/anura/core/PlayerMove.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.material.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PlayerMove implements Listener
|
||||
{
|
||||
private final AnuraCore plugin;
|
||||
public PlayerMove(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
Player p = event.getPlayer();
|
||||
Block block = event.getTo().clone().getBlock();
|
||||
Block under = block.getLocation().subtract(0,1,0).getBlock();
|
||||
|
||||
Location jumpIslandCenter = new Location(Bukkit.getWorld("lobby"), -289, 60, -1438);
|
||||
if(p.getWorld().getName().equals("lobby") && jumpIslandCenter.distance(event.getTo()) < 80 && (under.getType().equals(Material.GRASS)) && ((Entity)p).isOnGround() && !p.hasPermission("core.jump.grassStep"))
|
||||
{
|
||||
ResultSet rs = AnuraCore.getSql().querySelect("SELECT x,y,z FROM jumpLocs WHERE stage = (SELECT stage FROM jumpUsers WHERE userId = (SELECT id FROM players WHERE uuid = '"+p.getUniqueId().toString()+"') ORDER BY stage DESC LIMIT 1)");
|
||||
try {
|
||||
if(!rs.first())
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("lobby"), -262, 19, -1473);
|
||||
p.teleport(loc);
|
||||
return;
|
||||
}
|
||||
|
||||
double x = rs.getInt("x");
|
||||
double y = rs.getInt("y");
|
||||
double z = rs.getInt("z");
|
||||
if(x<0) x -= 0.5;
|
||||
else x += 0.5;
|
||||
if(z<0) z -= 0.5;
|
||||
else z += 0.5;
|
||||
Location loc = new Location(Bukkit.getWorld("lobby"), x, y, z);
|
||||
p.teleport(loc);
|
||||
API.statusMsg(p, "jump_tp_last_grass", true);
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
System.out.println(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(event.getTo().getY() <= -40 && plugin.getConfig().getBoolean("no-void-death"))
|
||||
{
|
||||
p.performCommand("spawn");
|
||||
}
|
||||
if(block.getType().equals(Material.CARPET) && under.getType().equals(Material.SIGN_POST))
|
||||
{
|
||||
p.setWalkSpeed(0.6F);
|
||||
}
|
||||
else if(block.getType().equals(Material.CARPET) && under.getType().equals(Material.ENDER_CHEST))
|
||||
{
|
||||
try {
|
||||
double X = under.getLocation().getX();
|
||||
double Y = under.getLocation().getY();
|
||||
double Z = under.getLocation().getZ();
|
||||
String world = under.getLocation().getWorld().getName();
|
||||
String sql = "SELECT * FROM coreJumpers WHERE X = '"+(int)X+"' AND Y = '"+(int)Y+"' AND Z = '"+(int)Z+"' AND world = '"+world+"' AND type = 'high'";
|
||||
ResultSet rs = AnuraCore.getSql().querySelect(sql);
|
||||
rs.last();
|
||||
if(rs.getRow() > 0)
|
||||
{
|
||||
p.setVelocity(new Vector(0,rs.getDouble("height"),0));
|
||||
ParticleEffect.FIREWORKS_SPARK.display(p.getLocation(), (float)0.1, (float)0.1, (float)0.1, (float)0.3, 10);
|
||||
}
|
||||
p.setWalkSpeed(0.2F);
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
else if(block.getType().equals(Material.CARPET) && under.getType().equals(Material.RAILS))
|
||||
{
|
||||
try {
|
||||
double X = under.getLocation().getX();
|
||||
double Y = under.getLocation().getY();
|
||||
double Z = under.getLocation().getZ();
|
||||
String world = under.getLocation().getWorld().getName();
|
||||
String sql = "SELECT * FROM coreJumpers WHERE X = '"+(int)X+"' AND Y = '"+(int)Y+"' AND Z = '"+(int)Z+"' AND world = '"+world+"' AND type = 'far'";
|
||||
ResultSet rs = AnuraCore.getSql().querySelect(sql);
|
||||
rs.last();
|
||||
if(rs.getRow() > 0)
|
||||
{
|
||||
p.setVelocity(p.getLocation().getDirection().multiply(new Vector(rs.getDouble("height"),1,rs.getDouble("height"))));
|
||||
p.setVelocity(p.getVelocity().setY(1.3));
|
||||
ParticleEffect.LAVA.display(p.getLocation(), (float)0.1, (float)0.1, (float)0.1, (float)0.3, 10);
|
||||
p.playSound(p.getLocation(), Sound.EXPLODE, 1, 1);
|
||||
}
|
||||
p.setWalkSpeed(0.2F);
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p.setWalkSpeed(0.2F);
|
||||
}
|
||||
Block sign = null;
|
||||
Block isSign = block.getLocation().getWorld().getBlockAt(block.getLocation().add(0, 1, 0));
|
||||
if(isSign.getType().equals(Material.WALL_SIGN))
|
||||
{
|
||||
sign = isSign;
|
||||
}
|
||||
else if(block.getType().equals(Material.WALL_SIGN))
|
||||
{
|
||||
sign = block;
|
||||
}
|
||||
if(sign != null && !event.getPlayer().hasPermission("core.rules.hideSign"))
|
||||
{
|
||||
Sign s = (Sign)sign.getState().getData();
|
||||
BlockFace bf = s.getFacing();
|
||||
if(bf.equals(BlockFace.EAST)) event.getPlayer().setVelocity(new Vector(0.3,0,0));
|
||||
if(bf.equals(BlockFace.WEST)) event.getPlayer().setVelocity(new Vector(-0.3,0,0));
|
||||
if(bf.equals(BlockFace.SOUTH)) event.getPlayer().setVelocity(new Vector(0,0,0.3));
|
||||
if(bf.equals(BlockFace.NORTH)) event.getPlayer().setVelocity(new Vector(0,0,-0.3));
|
||||
}
|
||||
if(!plugin.lastLoc.containsKey(p) || !plugin.lastLoc.get(p).getWorld().equals(p.getLocation().getWorld()) || plugin.lastLoc.get(p).distance(p.getLocation()) > 1)
|
||||
{
|
||||
plugin.pots.refreshPlayer(p);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
21
src/de/anura/core/PlayerQuit.java
Normal file
21
src/de/anura/core/PlayerQuit.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerQuit implements Listener
|
||||
{
|
||||
public PlayerQuit(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
event.setQuitMessage(null);
|
||||
AnuraCore.getInstance().endSitting(event.getPlayer());
|
||||
AnuraCore.getInstance().disableCommandsAdventure.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
49
src/de/anura/core/PlayerTeleport.java
Normal file
49
src/de/anura/core/PlayerTeleport.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Stairs;
|
||||
|
||||
public class PlayerTeleport implements Listener
|
||||
{
|
||||
public PlayerTeleport(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
if(plugin.sittingPlayer.containsKey(event.getPlayer()) && !event.getCause().equals(TeleportCause.PLUGIN))
|
||||
{
|
||||
if(event.getPlayer().isSneaking())
|
||||
{
|
||||
Player P = event.getPlayer();
|
||||
Block b = plugin.sittingBlocks.get(P);
|
||||
MaterialData md = b.getState().getData();
|
||||
if(md instanceof Stairs)
|
||||
{
|
||||
Stairs s = (Stairs)md;
|
||||
Location loc = b.getRelative(s.getFacing()).getLocation();
|
||||
Arrow a = plugin.sittingPlayer.get(P);
|
||||
event.setTo(loc);
|
||||
P.setSneaking(false);
|
||||
a.remove();
|
||||
plugin.sittingPlayer.remove(P);
|
||||
plugin.sittingBlocks.remove(P);
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
158
src/de/anura/core/ReflectionUtil.java
Normal file
158
src/de/anura/core/ReflectionUtil.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* ReflectionUtil v1.1
|
||||
*
|
||||
* You are welcome to use it, modify it and redistribute it under the condition to not claim this class as your own
|
||||
*
|
||||
* @author DarkBlade12
|
||||
*/
|
||||
public abstract class ReflectionUtil {
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||
|
||||
static {
|
||||
CORRESPONDING_TYPES.put(Byte.class, byte.class);
|
||||
CORRESPONDING_TYPES.put(Short.class, short.class);
|
||||
CORRESPONDING_TYPES.put(Integer.class, int.class);
|
||||
CORRESPONDING_TYPES.put(Long.class, long.class);
|
||||
CORRESPONDING_TYPES.put(Character.class, char.class);
|
||||
CORRESPONDING_TYPES.put(Float.class, float.class);
|
||||
CORRESPONDING_TYPES.put(Double.class, double.class);
|
||||
CORRESPONDING_TYPES.put(Boolean.class, boolean.class);
|
||||
}
|
||||
|
||||
public enum DynamicPackage {
|
||||
MINECRAFT_SERVER {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().substring(23, 30);
|
||||
}
|
||||
},
|
||||
CRAFTBUKKIT {
|
||||
@Override
|
||||
public String toString() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class FieldEntry {
|
||||
String key;
|
||||
Object value;
|
||||
|
||||
public FieldEntry(String key, Object value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||
}
|
||||
|
||||
private static Class<?>[] toPrimitiveTypeArray(Object[] objects) {
|
||||
int a = objects != null ? objects.length : 0;
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++)
|
||||
types[i] = getPrimitiveType(objects[i].getClass());
|
||||
return types;
|
||||
}
|
||||
|
||||
private static Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a = classes != null ? classes.length : 0;
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++)
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
return types;
|
||||
}
|
||||
|
||||
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||
if (a.length != o.length)
|
||||
return false;
|
||||
for (int i = 0; i < a.length; i++)
|
||||
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Class<?> getClass(String name, DynamicPackage pack, String subPackage) throws Exception {
|
||||
return Class.forName(pack + (subPackage != null && subPackage.length() > 0 ? "." + subPackage : "") + "." + name);
|
||||
}
|
||||
|
||||
public static Class<?> getClass(String name, DynamicPackage pack) throws Exception {
|
||||
return getClass(name, pack, null);
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... paramTypes) {
|
||||
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||
for (Constructor<?> c : clazz.getConstructors()) {
|
||||
Class<?>[] types = toPrimitiveTypeArray(c.getParameterTypes());
|
||||
if (equalsTypeArray(types, t))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object newInstance(Class<?> clazz, Object... args) throws Exception {
|
||||
return getConstructor(clazz, toPrimitiveTypeArray(args)).newInstance(args);
|
||||
}
|
||||
|
||||
public static Object newInstance(String name, DynamicPackage pack, String subPackage, Object... args) throws Exception {
|
||||
return newInstance(getClass(name, pack, subPackage), args);
|
||||
}
|
||||
|
||||
public static Object newInstance(String name, DynamicPackage pack, Object... args) throws Exception {
|
||||
return newInstance(getClass(name, pack, null), args);
|
||||
}
|
||||
|
||||
public static Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
|
||||
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||
for (Method m : clazz.getMethods()) {
|
||||
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
||||
if (m.getName().equals(name) && equalsTypeArray(types, t))
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object invokeMethod(String name, Class<?> clazz, Object obj, Object... args) throws Exception {
|
||||
return getMethod(name, clazz, toPrimitiveTypeArray(args)).invoke(obj, args);
|
||||
}
|
||||
|
||||
public static Field getField(String name, Class<?> clazz) throws Exception {
|
||||
return clazz.getDeclaredField(name);
|
||||
}
|
||||
|
||||
public static Object getValue(String name, Object obj) throws Exception {
|
||||
Field f = getField(name, obj.getClass());
|
||||
f.setAccessible(true);
|
||||
return f.get(obj);
|
||||
}
|
||||
|
||||
public static void setValue(Object obj, FieldEntry entry) throws Exception {
|
||||
Field f = getField(entry.getKey(), obj.getClass());
|
||||
f.setAccessible(true);
|
||||
f.set(obj, entry.getValue());
|
||||
}
|
||||
|
||||
public static void setValues(Object obj, FieldEntry... entrys) throws Exception {
|
||||
for (FieldEntry f : entrys)
|
||||
setValue(obj, f);
|
||||
}
|
||||
}
|
||||
137
src/de/anura/core/SignChange.java
Normal file
137
src/de/anura/core/SignChange.java
Normal file
@@ -0,0 +1,137 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
|
||||
public class SignChange implements Listener
|
||||
{
|
||||
public SignChange(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@EventHandler
|
||||
public void onSignChange(SignChangeEvent event)
|
||||
{
|
||||
|
||||
if(event.getLine(0).equalsIgnoreCase("[Warp]"))
|
||||
{
|
||||
if(!event.getPlayer().hasPermission("core.signs.warp"))
|
||||
{
|
||||
event.setLine(0, ChatColor.STRIKETHROUGH + "[Warp]");
|
||||
event.setLine(1, ChatColor.RED + "You don't");
|
||||
event.setLine(2, ChatColor.RED + "have");
|
||||
event.setLine(3, ChatColor.RED + "Permission!");
|
||||
return;
|
||||
}
|
||||
if(event.getLine(1).equalsIgnoreCase("warp"))
|
||||
{
|
||||
ResultSet rs = AnuraCore.sql.querySelect("SELECT name FROM coreWarps WHERE name = '"+event.getLine(2)+"'");
|
||||
try {
|
||||
rs.last();
|
||||
if(rs.getRow() == 0)
|
||||
{
|
||||
event.setLine(0, ChatColor.STRIKETHROUGH+ "[Warp]");
|
||||
event.setLine(1, ChatColor.RED + "Der Warp");
|
||||
event.setLine(2, ChatColor.YELLOW + event.getLine(2) + ChatColor.RED + "exis-");
|
||||
event.setLine(3, ChatColor.RED + "tiert nicht!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Location loc = event.getBlock().getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
AnuraCore.sql.queryUpdate("INSERT INTO coreWarpSigns(X,Y,Z,world,server,type,value,info) VALUES('"+X+"','"+Y+"','"+Z+"','"+world+"','"+server+"','warp','"+event.getLine(2)+"','"+event.getLine(3)+"')");
|
||||
event.setLine(0, "["+ChatColor.GREEN+"Warp"+ChatColor.BLACK+"]");
|
||||
event.setLine(1, ChatColor.DARK_GRAY+"--------");
|
||||
event.setLine(2, ChatColor.AQUA + event.getLine(2));
|
||||
event.setLine(3, ChatColor.BLUE + event.getLine(3));
|
||||
API.statusMsg(event.getPlayer(), "warpsign_created", true);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("Error: "+ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
else if(event.getLine(1).equalsIgnoreCase("spawn"))
|
||||
{
|
||||
Location loc = event.getBlock().getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
AnuraCore.sql.queryUpdate("INSERT INTO coreWarpSigns(X,Y,Z,world,server,type,value,info) VALUES('"+X+"','"+Y+"','"+Z+"','"+world+"','"+server+"','spawn','none','"+event.getLine(3)+"')");
|
||||
event.setLine(0, ChatColor.DARK_GRAY + "---------");
|
||||
event.setLine(1, ChatColor.BLACK + "["+ChatColor.GREEN + "Spawn"+ ChatColor.BLACK + "]");
|
||||
event.setLine(2, ChatColor.DARK_GRAY + "---------");
|
||||
event.setLine(3, ChatColor.BLUE + event.getLine(3));
|
||||
API.statusMsg(event.getPlayer(), "spawnsign_created", true);
|
||||
}
|
||||
else if(event.getLine(1).equalsIgnoreCase("server"))
|
||||
{
|
||||
Location loc = event.getBlock().getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = event.getLine(2);
|
||||
String curServer = plugin.getConfig().getString("server-name");
|
||||
AnuraCore.sql.queryUpdate("INSERT INTO coreWarpSigns(X,Y,Z,world,server,type,value,info) VALUES('"+X+"','"+Y+"','"+Z+"','"+world+"','"+curServer+"','server','"+server+"','"+event.getLine(3)+"')");
|
||||
event.setLine(0, ChatColor.BLACK + "["+ChatColor.GREEN + "Server"+ ChatColor.BLACK + "]");
|
||||
event.setLine(1, ChatColor.GREEN + "--"+ChatColor.DARK_GRAY+"/"+ChatColor.GREEN+"--");
|
||||
event.setLine(2, ChatColor.AQUA + event.getLine(2));
|
||||
event.setLine(3, ChatColor.BLUE + event.getLine(3));
|
||||
API.statusMsg(event.getPlayer(), "serversign_created", true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(event.getPlayer().hasPermission("core.signs.chars"))
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
String l = event.getLine(i);
|
||||
l = ChatColor.translateAlternateColorCodes('&', l);
|
||||
if(l.contains("%"))
|
||||
{
|
||||
String[] parts = l.split("%");
|
||||
ArrayList<Entry<String, String>> toReplace = new ArrayList<>();
|
||||
Boolean first = true;
|
||||
for(String s : parts)
|
||||
{
|
||||
if(!first)
|
||||
{
|
||||
String num = s.split(" ")[0];
|
||||
if(plugin.isInteger(num))
|
||||
{
|
||||
int number = Integer.valueOf(num);
|
||||
Entry<String, String> e = new SimpleEntry<>("%"+number, Character.toString((char)number));
|
||||
toReplace.add(e);
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
for(Entry<String, String> entry : toReplace)
|
||||
{
|
||||
l = l.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
event.setLine(i, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
27
src/de/anura/core/Tools.java
Normal file
27
src/de/anura/core/Tools.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class Tools {
|
||||
|
||||
/**
|
||||
* Sends a given message to a given player with the given status
|
||||
* @param p The player to send the message to
|
||||
* @param msg The message to send
|
||||
* @param positive If the message should be green(true) or red(false)
|
||||
*/
|
||||
public void sendStatusMsg(CommandSender p, String msg, Boolean positive)
|
||||
{
|
||||
ChatColor chatColor;
|
||||
if(positive)
|
||||
{
|
||||
chatColor = ChatColor.GREEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
chatColor = ChatColor.RED;
|
||||
}
|
||||
p.sendMessage(ChatColor.GRAY + "[Anura] "+chatColor+msg);
|
||||
}
|
||||
}
|
||||
25
src/de/anura/core/WeatherChange.java
Normal file
25
src/de/anura/core/WeatherChange.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package de.anura.core;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
|
||||
public class WeatherChange implements Listener
|
||||
{
|
||||
public WeatherChange(AnuraCore plugin)
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWeatherChange(WeatherChangeEvent event)
|
||||
{
|
||||
if(event.toWeatherState() && plugin.getConfig().getBoolean("no-rain"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
System.out.println("Stopped rain!");
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
72
src/plugin.yml
Normal file
72
src/plugin.yml
Normal file
@@ -0,0 +1,72 @@
|
||||
name: Core
|
||||
main: de.anura.core.AnuraCore
|
||||
version: 0.9
|
||||
author: kaenganxt
|
||||
softdepend: [Multiverse-Core]
|
||||
commands:
|
||||
setjumper:
|
||||
description: Admin Command
|
||||
usage: /<command> <height>
|
||||
setspawn:
|
||||
description: Sets the worlds spawn
|
||||
usage: /<command>
|
||||
spawn:
|
||||
description: Teleports you to spawn
|
||||
usage: /<command> <player>
|
||||
money:
|
||||
description: Money stuff
|
||||
usage: /<command> [pay <player> <money>]
|
||||
gm:
|
||||
description: GameMode!
|
||||
usage: /<command> <blabla>
|
||||
sun:
|
||||
description: I love sun!
|
||||
usage: /<command>
|
||||
core:
|
||||
description: Save/Reload the config
|
||||
usage: /<command> save|reload|debugclosemysql
|
||||
hilfe:
|
||||
description: Shows the help
|
||||
usage: /<command> [seite]
|
||||
none:
|
||||
description: This is a dummy command
|
||||
usage: /<command>
|
||||
flyspeed:
|
||||
description: Set the fly-speed
|
||||
usage: /<command> <speed>
|
||||
setwarp:
|
||||
description: Set a warp
|
||||
usage: /<command> <name> [allowUsers]
|
||||
warp:
|
||||
description: It's a warp
|
||||
usage: /<command> <warp> [player]
|
||||
remwarp:
|
||||
description: Remove warp
|
||||
usage: /<command> <warp>
|
||||
flowerpot:
|
||||
description: Set a flowerpot
|
||||
usage: /<command> <translateName>
|
||||
addmap:
|
||||
description: Adds an image-map
|
||||
usage: /<command> <imageName>
|
||||
rendermap:
|
||||
description: Renders an image for a map
|
||||
usage: /<command> <imageUrl> <name>
|
||||
cleararrows:
|
||||
description: Clears all arrows in the current world
|
||||
usage: /<command>
|
||||
stairmode:
|
||||
description: Toggles the stairmode
|
||||
usage: /<command>
|
||||
addcmd:
|
||||
description: Adds some text to a cmd block
|
||||
usage: /<command> <text>
|
||||
setcmd:
|
||||
description: Sets the command of a cmd block
|
||||
usage: /<command> <text>
|
||||
togglecommands:
|
||||
description: Only cmd block command!
|
||||
usage: /<command> <player> <enable|disable>
|
||||
updatecommandblocks:
|
||||
description: Updates command blocks at the given positions
|
||||
usage: /<command> {<x1>, <y1>, <z1>}...
|
||||
Reference in New Issue
Block a user