Skip to content

Commit

Permalink
1.8 Release (#40)
Browse files Browse the repository at this point in the history
* Let's get started... Again

Set the default values to "guiGadgetWorlds" to an empty array, just to allow users to use the plugin out-of-the-box. I've also added a new config option to allow the users to set whether the players can drop the gadget items or not.

Because of the added config option I've also added a new message to tell the players they cannot drop items.

* Gadget registration

Re-done how the gadgets are registered on the server. The main gadget class (Gadget.java) checks to see if it's already called the Gadget#registerEvent method and shouldn't call it multiple times.

* 1.8 Stable

Plugin should now be stable on 1.8.x servers (If not, then at least 1.8.4 and above).

* 1.8 Stable

Plugin should now be stable on 1.8.x servers (If not, then at least 1.8.4 and above).
  • Loading branch information
TGRHavoc authored Oct 5, 2016
1 parent 98fdcc0 commit 6be1fb5
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 326 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bin/
.project
.classpath
.settings
33 changes: 33 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
ChangeLog - Please create an issue to log your changes.
=====

### Bukkit 1.8.x Release
###### Date: 05-Oct-2016
###### Developer: TGRHavoc
- Set the default values to "guiGadgetWorlds" to an empty array, just to allow users to use the plugin out-of-the-box. I've also added a new config option to allow the users to set whether the players can drop the gadget items or not.

- Because of the added config option I've also added a new message to tell the players they cannot drop items.

- Re-done how the gadgets are registered on the server. The main gadget class (Gadget.java) checks to see if it's already called the Gadget#registerEvent method and shouldn't call it multiple times.

### Turned this into releasable, working plugin
###### Date: 21-Jul-2016
###### Developer: pookeythekid
- Recoded the entire paintball gun so that it uses packets now. This is much better at not destroying the contents of container blocks and signs.
- Also massively expanded PaintballGunListener's BlockData class (and made it its own separate class), though it turned out to be useless once I went to packets.

- Redesigned the gadget-adding system. Players now own their individual sets of Gadgets; each players' gadgets have their events registered **once**. Re-registering gadgets was a major bug.
- The MVPGadgets class's _availableGadgets_ contains ownerless gadgets, for the sake of seeing what they are without having redundant listeners registered.

- Added a few settings in messages.yml.

- Made a bunch of OCD edits throughout the code and config files.

- Wrote up an HTML file in the resources folder that covers all commands and permissions. Feel free to add to it if necessary.

- Did I say I fixed a crapton of bugs?

- Added commands /mvpgadgets reload and /gadget
- /gadget will swap your gadget out for the GUI Gadget and open the GUI display.

- Added config settings guiGadgetWorlds and guiGadgetSlot (I think the latter is correct, too lazy to check right now). Basically self-explanatory.

- Made gadgets functional after a plugin reload with players online, instead of the plugin vomiting NPEs everywhere.

### Disguises Updated
###### Date: 4-Oct-2015
###### Developer: TGRHavoc
Expand Down
17 changes: 14 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ Gadget_Prices:

# In which worlds will players receive the Gadget Selector gadget upon login?
# You should put your hub worlds in this setting. Delete the original list if you want to; it's just an example.
guiGadgetWorlds:
- Hub
- Spawn
# If you want gadgets to be usable in all worlds, set it to an empty list e.g. guiGadgetWorlds: []
# Example configuration:
# guiGadgetWorlds:
# - Spawn
# - Hub
guiGadgetWorlds: []

# Do you want the players to be able to drop their gadgets?
# If you do, set this to 'true'.
allowDropping: false

# In which slot in the player's hotbar should the Gadget Selector be placed? (5 is the middle)
guiGadgetSlot: 5

# In which slot in the player's hotbar should the other Gadgets be placed ( default = 6 )
gadgetSlot: 6

## Disguise Gadget Settings ##
# This is a list of mobs that the players can disguise as (Look at mob cannon settings for a list of mobs)
Disguises_List:
Expand Down
3 changes: 3 additions & 0 deletions messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Messages:
# the MVPGadgets config as hub worlds. Leave this as empty quotes to remove the message.
WRONG_WORLD: "&cYou are not in a hub world! An admin can change this in the MVPGadgets config."

# For when people try to throw a gadget when the throw_gadget option is set to false in the config file.
NO_THROW: "&cYou cannot throw gadgets on the floor! Who do you think you are, the Queen?"

Disguises:
# When a player disguises themselves
DISGUISED: "You are now disguised as a(n) {ENTITY}"
Expand Down
122 changes: 20 additions & 102 deletions src/ovh/tgrhavoc/mvpgadgets/MVPGadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashSet;
import java.util.Set;

import me.pookeythekid.mobcannon.MobCannon;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import me.pookeythekid.mobcannon.MobCannon;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import ovh.tgrhavoc.mvpgadgets.commands.GUIGadgetCommand;
import ovh.tgrhavoc.mvpgadgets.commands.MVPGadgetsCommand;
import ovh.tgrhavoc.mvpgadgets.events.GadgetHandler;
Expand All @@ -31,7 +27,6 @@
import ovh.tgrhavoc.mvpgadgets.gadgets.mobcannon.MobCannonGadget;
import ovh.tgrhavoc.mvpgadgets.gadgets.paintballgun.PaintballGunGadget;
import ovh.tgrhavoc.mvpgadgets.gadgets.paintballgun.PaintballListener;
import ovh.tgrhavoc.mvpvpgadgets.tests.JarUtil;
import ovh.tgrhavoc.utils.VaultUtil;

public class MVPGadgets extends JavaPlugin {
Expand All @@ -44,7 +39,9 @@ public class MVPGadgets extends JavaPlugin {
private static Economy economy = null;
private static Permission permission = null;

public static String nmsVersion = "v1_8_R3";
private static String nmsVersion = Bukkit.getServer().getClass().getPackage().getName()
.substring(23);


@Override
public void onDisable(){
Expand All @@ -61,9 +58,12 @@ public void onEnable(){

getServer().getPluginManager().registerEvents(new GadgetHandler(this), this);

registerGadgets();
//registerGadetEvents();
registerGadgets(); // Gadgets should register their own events.

registerCommands();

Bukkit.getLogger().info("Hey, our NMS version is " + nmsVersion);

}

private void registerGadgets() {
Expand All @@ -76,11 +76,7 @@ private void registerGadgets() {

addGadget(new GUIGadget(this));
}
@SuppressWarnings("unused")
@Deprecated
private void registerGadetEvents() {
getServer().getPluginManager().registerEvents(paintListener, this); //Going to keep this here for now.
}

private void registerCommands(){
getCommand("gadget").setExecutor(new GUIGadgetCommand(this));
getCommand("mvpgadgets").setExecutor(new MVPGadgetsCommand(this));
Expand Down Expand Up @@ -131,7 +127,7 @@ private void writeToFile(InputStream in, File file) throws IOException{

/**
* Get the messages.yml file in a YamlConfiguration class.
* @return YamlConfiguration that represnts the Messages.yml file in the resources folder
* @return YamlConfiguration that represents the Messages.yml file in the resources folder
*/
public YamlConfiguration getMessages(){
return messages;
Expand Down Expand Up @@ -164,14 +160,7 @@ public static void addGadgetStatic(Gadget g){
Bukkit.getLogger().info("Someone tried to register a gadget that already exists");
return;
}
if (g.getOwningPlayer() != null) {
try {
// add simple-constructed gadget, not the kind that has its events registered
Gadget gadget = g.getClass().getConstructor(MVPGadgets.class).newInstance(g.getPlugin());
availableGadgets.add(gadget);
return;
} catch (Exception ex){ ex.printStackTrace(); }
}

availableGadgets.add(g);
}

Expand All @@ -184,14 +173,7 @@ public void addGadget(Gadget g){
Bukkit.getLogger().info("Someone tried to register a gadget that already exists");
return;
}
if (g.getOwningPlayer() != null) {
try {
// add simple-constructed gadget, not the kind that has its events registered
Gadget gadget = g.getClass().getConstructor(MVPGadgets.class).newInstance(g.getPlugin());
availableGadgets.add(gadget);
return;
} catch (Exception ex){ ex.printStackTrace(); }
}

availableGadgets.add(g);
}

Expand Down Expand Up @@ -252,6 +234,7 @@ private void initVault(){
Bukkit.getLogger().info("Vault permissions hooked");
VaultUtil.setPlugin(this);
}

private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider =
getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
Expand All @@ -262,6 +245,7 @@ private boolean setupPermissions() {
return false;
return (permission != null);
}

private boolean setupEconomy(){
RegisteredServiceProvider<Economy> economyProvider =
getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
Expand All @@ -271,74 +255,8 @@ private boolean setupEconomy(){
return (economy != null);
}
//End vault hook

//Method which loads .class files found in the "mods" folder so you can dynamically add or remove gadgets
@SuppressWarnings({ "unused", "unchecked" })
@Deprecated
private void loadGadgetClasses() {
File basePath = new File(this.getDataFolder() + "/mods");
File[] files = new File(this.getDataFolder() + "/mods").listFiles();

boolean shouldLoad = true;

ClassLoader cl = null;

try {
URL url = basePath.toURL();
URL[] urls = new URL[]{url};
cl = new URLClassLoader(urls);
} catch (Exception e) {
shouldLoad = false;
e.printStackTrace();
}

if (shouldLoad) {
for (File file : files) {
String fileName = file.getName();
//If it is not a .class file contiue to the next entry.
if (!fileName.split(".")[fileName.split(".").length - 1].equals(".class")) continue;

try {

@SuppressWarnings("rawtypes")
Class clazz = cl.loadClass(fileName.replace(".class",""));
//Our .class file extends Gadget
if(clazz.isAssignableFrom(Gadget.class)){
Gadget gadget = (Gadget) clazz.newInstance();
addGadget(gadget);
}

} catch (Exception e) {

}
}
}
}

@Deprecated
public void test(){
for (String s: JarUtil.getGadetClasses(this.getDataFolder().getParent() + "/MVPGadgets.jar")){
try {
System.out.println("Constructing... " + s);

if (s.contains("\\$[0-9]"))
System.out.println("Found funny class: " + s);

Class<?> gadgetClass = Class.forName(s);
Constructor<?> constr = gadgetClass.getConstructor();
Gadget gadgetFromClass = null;
if (constr.getParameterTypes().length > 0){
System.out.println("Found aruments for " + s);

}else{ // No constructor args (Assume it's a gadget)
gadgetFromClass = (Gadget)constr.newInstance();
}

//addGadget(gadgetFromClass);
System.out.println("Just added a gadget " + gadgetFromClass);
} catch (Exception e) {
e.printStackTrace();
}
}

public static String getNmsVersion(){
return nmsVersion;
}
}
60 changes: 17 additions & 43 deletions src/ovh/tgrhavoc/mvpgadgets/commands/GUIGadgetCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package ovh.tgrhavoc.mvpgadgets.commands;

import java.util.UUID;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import ovh.tgrhavoc.mvpgadgets.MVPGadgets;
import ovh.tgrhavoc.mvpgadgets.gadgets.Gadget;
import ovh.tgrhavoc.mvpgadgets.gadgets.guigadget.GUIGadget;
import ovh.tgrhavoc.mvpgadgets.gadgets.guigadget.GUIGadgetListener;

Expand All @@ -32,48 +29,25 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
else {
Player player = (Player) sender;
try {
// don't want to open a gadget GUI if the player isn't in a hub world
if (plugin.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) {
player.openInventory(GUIGadgetListener.getInv(player));
int slot;
if (plugin.getConfig().getInt("guiGadgetSlot") < 1)
slot = 0;
else if (plugin.getConfig().getInt("guiGadgetSlot") > 9)
slot = 8;
else slot = plugin.getConfig().getInt("guiGadgetSlot") - 1;

GUIGadget guiGadget = new GUIGadget(plugin);
player.getInventory().setItem(slot, guiGadget.getItemStack());
} else if (!plugin.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty())
player.sendMessage(plugin.getMessageFromConfig("Messages.WRONG_WORLD"));
} catch (NullPointerException npe) {
// player probably didn't log into the server via a hub world listed in the config, so gadgets didn't register
// either that, or the server reloaded with players online
for (Gadget gadget : plugin.getGadgets()){
try {
gadget.getClass().getConstructor(MVPGadgets.class, UUID.class).newInstance(
gadget.getPlugin(), player.getUniqueId());
} catch (Exception ex){ ex.printStackTrace(); }
}

// don't want to open a gadget GUI if the player isn't in a hub world
if ( plugin.getConfig().getStringList("guiGadgetWorlds").size() == 0 ||
plugin.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) {
player.openInventory(GUIGadgetListener.getInv(player));

int slot;
if (plugin.getConfig().getInt("gadgetSlot") <= 1)
slot = 0;
else if (plugin.getConfig().getInt("gadgetSlot") >= 9)
slot = 8;
else slot = plugin.getConfig().getInt("gadgetSlot") - 1;

// yay, copy-pasted code because a tired programmer is a lazy one
// but hey, a lazy programmer is a great one am i rite
if (plugin.getConfig().getStringList("guiGadgetWorlds").contains(player.getWorld().getName())) {
player.openInventory(GUIGadgetListener.getInv(player));
int slot;
if (plugin.getConfig().getInt("guiGadgetSlot") < 1)
slot = 0;
else if (plugin.getConfig().getInt("guiGadgetSlot") > 9)
slot = 8;
else slot = plugin.getConfig().getInt("guiGadgetSlot") - 1;

GUIGadget guiGadget = new GUIGadget(plugin);
player.getInventory().setItem(slot, guiGadget.getItemStack());
} else if (!plugin.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty())
player.sendMessage(plugin.getMessageFromConfig("Messages.WRONG_WORLD"));
GUIGadget guiGadget = new GUIGadget(plugin);
player.getInventory().setItem(slot, guiGadget.getItemStack());

}
} else if (!plugin.getMessageFromConfig("Messages.WRONG_WORLD").isEmpty())
player.sendMessage(plugin.getMessageFromConfig("Messages.WRONG_WORLD"));

}
}

Expand Down
Loading

0 comments on commit 6be1fb5

Please sign in to comment.