How to make a combat tag plugin?

Status
This thread has been locked.

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Hello - if anyone can give me some ideas on how to do this.

I only want a simple combat tag, no NPC, kill on leave etc.

I can code but I am having some problems with ideas of how to make it, if that makes sense..


Thank you
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Create a HasMap then add them to it like this:
Code:
    private WeakHashMap<Player, Integer> combatLog;
Make method:
    public void addCombat(final Player p, final int time) {
        this.combatLog.put(p, time);
    }
    @SuppressWarnings("deprecation")
    @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
    public void onDamage(final EntityDamageByEntityEvent e) {
        if (e.getEntity() instanceof Player) {
            final Player p = (Player)e.getEntity();
            Player d = null;
            if (e.getDamager() instanceof Player) {
                d = (Player)e.getDamager();
            }
            else if (e.getDamager() instanceof Projectile) {
                final Projectile proj = (Projectile)e.getDamager();
                if (proj.getShooter() instanceof Player) {
                    d = (Player)proj.getShooter();
                }
            }
            if (d == null || d.equals(p)) {
                return;
            }
            if (!this.combatLog.containsKey(p)) {
                p.sendMessage(ChatColor.RED + "You are now combat tagged.");
            }
            if (!this.combatLog.containsKey(d)) {
                d.sendMessage(ChatColor.RED + "You are now combat tagged.");
            }
            this.addCombat(p, 45);
            this.addCombat(d, 45);
        }
    }
I dont think I'm skilled enough to attempt this yet, but thank you.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
HashMaps are pretty basic but I guess okay :/
Yes, but making the count down, and some of it I simply don't understand.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Jaliyiah

Feedback score
0
Posts
15
Reactions
0
Resources
0
Hello - if anyone can give me some ideas on how to do this.

I only want a simple combat tag, no NPC, kill on leave etc.

I can code but I am having some problems with ideas of how to make it, if that makes sense..


Thank you
Clarification: In this case, 0 = false and 1 = true

- Use an entity damage entity event
- Check if both entities are players
- Make a HashMap for <Player, Integer> and another for <Player, BukkitRunnable> to store the Combat Tag time value
- Initialize the HashMaps in the onEnable method
- If the player is already in combat tag (combatTag.get(p, 1)) and they call another entity damage entity event, then make a runnable and reset the timer. If they are not in combat yet (combatTag.get(p, 0)) and they call an entity damage entity event, then make a runnable and set the timer to whatever time value you want to.

If you're still confused, PM me your Skype and I can help you out. I know I didn't explain myself very well but it'll be easier for me to show you the code and explain what it does, if that's what you want.
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Clarification: In this case, 0 = false and 1 = true

- Use an entity damage entity event
- Check if both entities are players
- Make a HashMap for <Player, Integer> and another for <Player, BukkitRunnable> to store the Combat Tag time value
- Initialize the HashMaps in the onEnable method
- If the player is already in combat tag (combatTag.get(p, 1)) and they call another entity damage entity event, then make a runnable and reset the timer. If they are not in combat yet (combatTag.get(p, 0)) and they call an entity damage entity event, then make a runnable and set the timer to whatever time value you want to.

If you're still confused, PM me your Skype and I can help you out. I know I didn't explain myself very well but it'll be easier for me to show you the code and explain what it does, if that's what you want.
mc.archie is my Skype :).
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Bryce

Senior Java & Full-Stack Developer
Supreme
Feedback score
18
Posts
678
Reactions
934
Resources
19
Simple. If you do not know how to use hashmaps, Use an arraylist with a String object type.

E.g

Code:
ArrayList<String> playersInCombat = new ArrayList<>();

Then when a player is hit, or tagged into combat, you can run

Code:
 playersInCombat.Add(player.getName());
.

Later on, you will need to hook into worldguard (easiest in my opinion, you can use your own regions in your plugin, but i prefer to use WG regions.) And when the player enters the region (Player Move event, Check if the player enters a specific region) check if the ArrayList you made contains the player.

Code:
 if (playersInCombat.contains(player.getName()){
// I dont know, kill them? bounce them away, completely up to you.
}

Same thing goes for logging out. Use the playerDisconnectEvent (90% sure thats not the actual event name, i am typing this from the top of my head) and basically same thing, check if the player is in the array list, and if so kill the player, drop his/her's shit.

Lastly when you need to remove the user from being tagged you can do playersInCombat.remove(p.getName()); to remove them from the list. (put that in a bukkit runnable (not recommended) or some sort of timing method)

You may be thinking, Well how am i going to keep track of individual players combat times? Well i have a class i use for like every plugin that has cooldowns, and basically you can create a Cooldown (timer) for like anything you want. And you can name it something. IN this case you would name it after a player!

Cooldown class:

Create a new cooldowns object

Code:
 Cooldowns cd = new CoolDowns();

Then basically you can check timers like this:

Code:
if (cd.tryCooldown(p, "CombatTag", 60 * 1000)){
// If the player doesnt have a current cooldown running (timer
// If the player didnt have a cooldown (which he didnt) a new cooldown
// will automatically be made when this code runs!
}else{
// Player has a cooldown running. Means the player MUST be tagged.
}

Lastly, you can do things such as:

Code:
p.sendMessage("You have: "+cd.getCooldown(p,"CombatTag")+" Seconds left!");

So yeah. hope it helps!
 
Last edited:

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Simple. If you do not know how to use hashmaps, Use an arraylist with a String object type.

E.g

Code:
ArrayList<String> playersInCombat = new ArrayList<>();

Then when a player is hit, or tagged into combat, you can run

Code:
 playersInCombat.Add(player.getName());
.

Later on, you will need to hook into worldguard (easiest in my opinion, you can use your own regions in your plugin, but i prefer to use WG regions.) And when the player enters the region (Player Move event, Check if the player enters a specific region) check if the ArrayList you made contains the player.

Code:
 if (playersInCombat.contains(player.getName()){
// I dont know, kill them? bounce them away, completely up to you.
}[CODE]

Same thing goes for logging out. Use the playerDisconnectEvent (90% sure thats not the actual event name, i am typing this from the top of my head) and basically same thing, check if the player is in the array list, and if so kill the player, drop his/her's shit.

Lastly when you need to remove the user from being tagged you can do playersInCombat.remove(p.getName()); to remove them from the list. (put that in a bukkit runnable (not recommended) or some sort of timing method)
Right. Thank you.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Bryce

Senior Java & Full-Stack Developer
Supreme
Feedback score
18
Posts
678
Reactions
934
Resources
19
Right. Thank you.

If have gone an edited it. I forgot about logging the players tag time :p

I included a class i use in almost every plugin i make that uses some sort of cooldown/timer. This class will help you wonders. Seriously. So go through and re-read what i changed at the bottom of my post and let me know what you think![DOUBLEPOST=1455225881,1455225701][/DOUBLEPOST]
your dumb
!- Initialize the HashMaps in the onEnable method"
lol[DOUBLEPOST=1455225225,1455225195][/DOUBLEPOST]
why tf would you use arraylists are you dumb?

Re-read my post. It has been updated.

I personally would use a hashmap. This user does not know hashmaps. So the first thing i learned in schooling was ArrayLists, hence why i brought them up because there is a high chance of the user knowing this instead.
 

Chearful

thomas.gg
Supreme
Feedback score
115
Posts
1,398
Reactions
2,236
Resources
0
This is just coming from Skript knowledge but here's something along the lines of what I'd do if I wasn't fussed about performance:

On damage - set {combattag.%player%.inct} to true. Set {combattag.%player%.cd} to 45
Every 1 sec - loop all players. If {combattag.%loop-player%.inct} is true - remove 1 from {combattag.%loop-player%.cd} - if {combattag.%loop-player%.cd} is 0 - message "&aur out of ct"
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
I understand hash maps, just it's a lot to do and think about.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Jaliyiah

Feedback score
0
Posts
15
Reactions
0
Resources
0
your dumb
!- Initialize the HashMaps in the onEnable method"
lol[DOUBLEPOST=1455225225,1455225195][/DOUBLEPOST]
why tf would you use arraylists are you dumb?
You have a better idea? Why don't you tell us how to do it, smart-ass? Wait, no, you have to be smart in order to be a smart-ass in the first place. Go flame somewhere else you degenerate fool.
 
Status
This thread has been locked.
Top