Permissions among other things. v04.1.

This commit is contained in:
nossr50 2011-02-09 15:54:08 -08:00
parent b38c682c8c
commit 1798a9ff39
7 changed files with 151 additions and 50 deletions

View File

@ -1,7 +1,7 @@
package com.bukkit.nossr50.mcMMO;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -9,7 +9,9 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class mcConfig {
private static volatile mcConfig instance;
private static volatile mcConfig instance;
String location = "mcmmo.properties";
protected static final Logger log = Logger.getLogger("Minecraft");
static ArrayList<String> adminChatList = new ArrayList<String>();
static ArrayList<Block> blockWatchList = new ArrayList<Block>();
static ArrayList<String> partyChatList = new ArrayList<String>();

View File

@ -88,13 +88,13 @@ public class mcEntityListener extends EntityListener {
defender.setHealth(calculateDamage(defender, 8));
}
//XP
if(x instanceof Skeleton && Math.random() * 10 > 8){
if(x instanceof Skeleton && Math.random() * 100 > 95){
if(defender.getHealth() != 0){
mcUsers.getProfile(attacker).skillUpUnarmed(1);
attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")");
}
}
if(x instanceof Spider&& Math.random() * 10 > 7){
if(x instanceof Spider&& Math.random() * 10 > 9){
if(defender.getHealth() != 0){
mcUsers.getProfile(attacker).skillUpUnarmed(1);
attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")");
@ -106,7 +106,7 @@ public class mcEntityListener extends EntityListener {
attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")");
}
}
if(x instanceof Creeper && Math.random() * 10 > 7){
if(x instanceof Creeper && Math.random() * 100 > 90){
if(defender.getHealth() != 0){
mcUsers.getProfile(attacker).skillUpUnarmed(2);
attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 2. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")");

View File

@ -2,6 +2,8 @@ package com.bukkit.nossr50.mcMMO;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijiko.Messaging;
import com.nijiko.permissions.PermissionHandler;
import com.nijiko.permissions.Control;
import com.nijikokun.bukkit.Permissions.Permissions;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
@ -26,7 +28,8 @@ public class mcMMO extends JavaPlugin {
private final mcEntityListener entityListener = new mcEntityListener(this);
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
private final String name = "mcMMO";
public static PermissionHandler Permissions = null;
public static PermissionHandler PermissionsHandler = null;
private Permissions permissions;
public mcMMO(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader);
@ -50,21 +53,23 @@ public class mcMMO extends JavaPlugin {
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, playerListener, Priority.Normal, this);
//Displays a message when plugin is loaded
PluginDescriptionFile pdfFile = this.getDescription();
mcPermissions.initialize(getServer());
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
}
public void setupPermissions() {
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
if(this.Permissions == null) {
if(this.PermissionsHandler == null) {
if(test != null) {
this.Permissions = ((Permissions)test).getHandler();
this.PermissionsHandler = ((Permissions)test).getHandler();
} else {
log.info(Messaging.bracketize(name) + " Permission system not enabled. Disabling plugin.");
this.getServer().getPluginManager().disablePlugin(this);
}
}
}
public Permissions getPermissions() {
return permissions;
}
public void onDisable() {
System.out.println("mcMMO disabled.");
}

View File

@ -0,0 +1,87 @@
package com.bukkit.nossr50.mcMMO;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.nijikokun.bukkit.Permissions.Permissions;
public class mcPermissions {
//Thanks to myWarp source code for helping me figure this shit out!
private static Permissions permissionsPlugin;
private static boolean permissionsEnabled = false;
private static volatile mcPermissions instance;
public static void initialize(Server server) {
Plugin test = server.getPluginManager().getPlugin("Permissions");
if (test != null) {
Logger log = Logger.getLogger("Minecraft");
permissionsPlugin = ((Permissions) test);
permissionsEnabled = true;
log.log(Level.INFO, "[mcMMO] Permissions enabled.");
} else {
Logger log = Logger.getLogger("Minecraft");
log.log(Level.SEVERE, "[mcMMO] Permissions isn't loaded, there are no restrictions.");
}
}
private boolean permission(Player player, String string) {
return permissionsPlugin.Security.permission(player, string);
}
public boolean motd(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.motd");
} else {
return true;
}
}
public boolean mySpawn(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.myspawn");
} else {
return true;
}
}
public boolean partyChat(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.chat.partychat");
} else {
return true;
}
}
public boolean partyTeleport(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.ptp");
} else {
return true;
}
}
public boolean whois(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.whois");
} else {
return true;
}
}
public boolean party(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.party");
} else {
return true;
}
}
public boolean adminChat(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.chat.adminchat");
} else {
return true;
}
}
public static mcPermissions getInstance() {
if (instance == null) {
instance = new mcPermissions();
}
return instance;
}
}

View File

@ -12,6 +12,8 @@ import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import com.nijikokun.bukkit.Permissions.Permissions;
public class mcPlayerListener extends PlayerListener {
public Location spawn = null;
private mcMMO plugin;
@ -21,10 +23,10 @@ public class mcPlayerListener extends PlayerListener {
}
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if(mcPermissions.getInstance().mySpawn(player)){
if(mcUsers.getProfile(player).getMySpawn(player) != null);
event.setRespawnLocation(mcUsers.getProfile(player).getMySpawn(player));
if(spawn != null)
event.setRespawnLocation(spawn);
}
}
public Player[] getPlayersOnline() {
return plugin.getServer().getOnlinePlayers();
@ -74,8 +76,10 @@ public class mcPlayerListener extends PlayerListener {
public void onPlayerJoin(PlayerEvent event) {
Player player = event.getPlayer();
mcUsers.addUser(player);
if(mcPermissions.getInstance().motd(player)){
player.sendMessage(ChatColor.BLUE + "This server is running mcMMO "+plugin.getDescription().getVersion()+" type "+ChatColor.YELLOW+"/mcmmo "+ChatColor.BLUE+ "for help.");
player.sendMessage(ChatColor.RED+"WARNING: "+ChatColor.DARK_GRAY+ "Using /myspawn will clear your inventory!");
player.sendMessage(ChatColor.RED+"WARNING: "+ChatColor.DARK_GRAY+ "Using /myspawn will clear your inventory!");
}
}
//Check if string is a player
@ -168,7 +172,7 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.GREEN+"Gaining Skill: "+ChatColor.DARK_GRAY+"Chop down trees.");
player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~");
player.sendMessage(ChatColor.GRAY+"Double Drops start to happen at 10 woodcutting skill");
player.sendMessage(ChatColor.GRAY+"it gets more frequent from there.");
player.sendMessage(ChatColor.GRAY+"and it gets more frequent from there.");
}
if(split[0].equalsIgnoreCase("/mining")){
event.setCancelled(true);
@ -197,7 +201,7 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.GREEN+"~~EFFECTS~~");
player.sendMessage(ChatColor.GRAY+"Damage scales with unarmed skill. The first damage increase");
player.sendMessage(ChatColor.DARK_GRAY+"happens at 50 skill. At very high skill levels, you will");
player.sendMessage(ChatColor.DARK_GRAY+"gain a proc to disarm opponents on hit");
player.sendMessage(ChatColor.DARK_GRAY+"gain a proc to disarm player opponents on hit");
}
if(split[0].equalsIgnoreCase("/herbalism")){
event.setCancelled(true);
@ -253,11 +257,15 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.GRAY+"/mining - displays info about the skill");
player.sendMessage(ChatColor.GRAY+"/repair - displays info about the skill");
player.sendMessage(ChatColor.GRAY+"/unarmed - displays info about the skill");
player.sendMessage(ChatColor.GRAY+"/herbalist - displays info about the skill");
player.sendMessage(ChatColor.GRAY+"/herbalism - displays info about the skill");
player.sendMessage(ChatColor.GRAY+"/excavation - displays info about the skill");
}
if(mcUsers.getProfile(player).inParty() && split[0].equalsIgnoreCase("/ptp")){
event.setCancelled(true);
if(!mcPermissions.getInstance().partyTeleport(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
if(split.length < 2){
player.sendMessage(ChatColor.RED+"Usage is /ptp <playername>");
return;
@ -271,7 +279,7 @@ public class mcPlayerListener extends PlayerListener {
}
}
}
if(player.isOp() && split[0].equalsIgnoreCase("/whois")){
if((player.isOp() || mcPermissions.getInstance().whois(player)) && split[0].equalsIgnoreCase("/whois")){
event.setCancelled(true);
if(split.length < 2){
player.sendMessage(ChatColor.RED + "Proper usage is /whois <playername>");
@ -304,6 +312,10 @@ public class mcPlayerListener extends PlayerListener {
}
}
if(split[0].equalsIgnoreCase("/setmyspawn")){
if(!mcPermissions.getInstance().mySpawn(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
double x = player.getLocation().getX();
double y = player.getLocation().getY();
@ -311,11 +323,6 @@ public class mcPlayerListener extends PlayerListener {
mcUsers.getProfile(player).setMySpawn(x, y, z);
player.sendMessage(ChatColor.DARK_AQUA + "Myspawn has been set to your current location.");
}
if(player.isOp() && split[0].equalsIgnoreCase("/setspawn")){
event.setCancelled(true);
spawn = player.getLocation();
player.sendMessage("Spawn set to current location");
}
if(split[0].equalsIgnoreCase("/stats")){
event.setCancelled(true);
player.sendMessage(ChatColor.DARK_GREEN + "mcMMO stats");
@ -328,6 +335,10 @@ public class mcPlayerListener extends PlayerListener {
}
//Party command
if(split[0].equalsIgnoreCase("/party")){
if(!mcPermissions.getInstance().party(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(split.length == 1 && !mcUsers.getProfile(player).inParty()){
player.sendMessage("Proper usage is /party <name> or 'q' to quit");
@ -365,6 +376,10 @@ public class mcPlayerListener extends PlayerListener {
}
}
if(split[0].equalsIgnoreCase("/p")){
if(!mcPermissions.getInstance().party(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(mcConfig.getInstance().isAdminToggled(player.getName()))
mcConfig.getInstance().toggleAdminChat(playerName);
@ -375,7 +390,11 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.GREEN + "Party Chat Toggled " + ChatColor.RED + "Off");
}
}
if(split[0].equalsIgnoreCase("/a") && player.isOp()){
if(split[0].equalsIgnoreCase("/a") && (player.isOp() || mcPermissions.getInstance().adminChat(player))){
if(!mcPermissions.getInstance().adminChat(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(mcConfig.getInstance().isPartyToggled(player.getName()))
mcConfig.getInstance().togglePartyChat(playerName);
@ -387,6 +406,10 @@ public class mcPlayerListener extends PlayerListener {
}
}
if(split[0].equalsIgnoreCase("/myspawn")){
if(!mcPermissions.getInstance().mySpawn(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(mcUsers.getProfile(player).getMySpawn(player) != null){
player.getInventory().clear();
@ -397,15 +420,6 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.RED+"Configure your myspawn first with /setmyspawn");
}
}
if(split[0].equalsIgnoreCase("/spawn")){
event.setCancelled(true);
if(spawn != null){
player.teleportTo(spawn);
player.sendMessage("Welcome to spawn, home of the feeble.");
return;
}
player.sendMessage("Spawn isn't configured. Have an OP set it with /setspawn");
}
}
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
@ -430,7 +444,7 @@ public class mcPlayerListener extends PlayerListener {
}
return;
}
if(player.isOp() && mcConfig.getInstance().isAdminToggled(player.getName())){
if((player.isOp() || mcPermissions.getInstance().adminChat(player)) && mcConfig.getInstance().isAdminToggled(player.getName())){
event.setCancelled(true);
for(Player herp : plugin.getServer().getOnlinePlayers()){
if(herp.isOp()){
@ -439,12 +453,5 @@ public class mcPlayerListener extends PlayerListener {
}
return;
}
if(player.isOp()){
event.setCancelled(true);
for(Player derp : plugin.getServer().getOnlinePlayers()){
String z = ChatColor.RED + "<" + ChatColor.WHITE + player.getName() + ChatColor.RED + "> "+ChatColor.WHITE;
derp.sendMessage(z+event.getMessage());
}
}
}
}

View File

@ -358,7 +358,7 @@ public class mcm {
}
//DIRT SAND OR GRAVEL
if(type == 3 || type == 13 || type == 2){
if(Math.random() * 10 > 9){
if(Math.random() * 100 > 95){
mcUsers.getProfile(player).skillUpExcavation(1);
player.sendMessage(ChatColor.YELLOW+"Excavation skill increased by 1. Total ("+mcUsers.getProfile(player).getExcavationInt()+")");
@ -411,14 +411,6 @@ public class mcm {
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
//CHANCE TO GET COAL
if(mcUsers.getProfile(player).getExcavationInt() > 125){
if(Math.random() * 2000 > 1999){
mat = Material.getMaterial(263);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
}
}
//GRASS OR DIRT
if((type == 2 || type == 3) && mcUsers.getProfile(player).getExcavationInt() > 25){
@ -446,6 +438,14 @@ public class mcm {
loc.getWorld().dropItemNaturally(loc, is);
}
}
//CHANCE TO GET COAL
if(mcUsers.getProfile(player).getExcavationInt() > 125){
if(Math.random() * 100 > 99){
mat = Material.getMaterial(263);
is = new ItemStack(mat, 1, (byte)0, (byte)0);
loc.getWorld().dropItemNaturally(loc, is);
}
}
}
}
public void woodCuttingProcCheck(Player player, Block block, Location loc){

View File

@ -1,3 +1,3 @@
name: mcMMO
main: com.bukkit.nossr50.mcMMO.mcMMO
version: 0.3.4
version: 0.4.1